I'm new here so I apologize for any errors in my question.
I'm writing a powershell script to uninstall a program, I need it to send keys to that program to click through the parts asking for user inputs. Problem is that my script calls to a process that has a duplicate name, it cant differentiate between the two. Only difference is how much memory it is using. Is there a way to select the process based on how much memory it is taking up? I appreciate any help.

$a = Get-Process | ?{$_.name -eq 'setup'}
$wshell = New-Object -ComObject wscript.shell;
$wshell.appactivate($a.Id)
Start-Sleep 5
$wshell.sendkeys('~',10)
$wshell.sendkeys('~',5)
CodePudding user response:
Two things to note up front:
Trying to automate applications by simulated user input, such as by sending keystrokes, is inherently brittle, and should only be used as a last resort.
- In the case at hand, see if
setup.exesupports parameters that obviate the need for interactive responses.
- In the case at hand, see if
The
.SendKeys()method has no documented second parameter - what do you think that does?
To get the process of interest, try the following:
$a = Get-Process setup |
Sort-Object -Descending WorkingSet64 |
Select-Object -First 1
For additional robustness, consider filtering the set of candidate processes by their .StartTime property.
