I have a script I’m working on that asks for a machine name, and then produces a list of running processes on that machine. From there it asks the user I they want to kill a process on that machine. If they select Yes, it prompts the user to type in the name of the process and is supposed to kill it. Here is the code I have so far:
Get-Process -ComputerName $machine | Out-GridView Write-Host $message = Write-Host "Do you want to kill a process?" -foregroundcolor Green Write-Host $yes = New-Object System.Management.Automation.Host.ChoiceDescription "&Yes" $no = New-Object System.Management.Automation.Host.ChoiceDescription "&No" $options = [System.Management.Automation.Host.ChoiceDescription[]][$yes, $no] $result = $host.ui.PromptForChoice[$title, $message, $options, 0] switch [$result] { 0{ $process = Read-Host 'What is the process name?' Write-Host Write-Host "Killing Process..." -ForegroundColor Yellow Invoke-Command -ComputerName $machine {Stop-Process -ProcessName $process} } }
I’m not sure what parameter called ‘Name’ it is referring to but my eyes have gone cross-eyed looking at this so maybe I’m missing something obvious?