adamknight
(ITcrackerjack)
1
Description
A script to view running processes on remote computer as well as the option to kill a process. It will prompt you for your domain username/password as well as the remote computer name.
The enableWinRM function calls the script found here: http://community.spiceworks.com/scripts/show/2703-remotely-enable-winrm-powershell
Let me know if you have any suggestions/questions!
Source Code
cls
Write-Host 'View/Kill Processes Remotely.'
$global:adminCreds = $host.ui.PromptForCredential("Need credentials", "Please enter your user name and password.", "", "")
$global:ComputerName = $null
Function enableWinRM {
$global:ComputerName = Read-Host 'Computer Name?'
#Remotely Enable WinRM (uses PSExec)
.\remotely_enable_winrm.ps1 -computerName $global:ComputerName
if ($LastExitCode -ne 0) {
enableWinRM
}
}
Function displayMenu (){
$title = "List or Kill"
$message = "Do you want to list the processes on the computer or kill one?"
# Options
$list = New-Object System.Management.Automation.Host.ChoiceDescription "&list", "List all processes on the computer"
$kill = New-Object System.Management.Automation.Host.ChoiceDescription "&kill", "Kills a process."
$exit = New-Object System.Management.Automation.Host.ChoiceDescription "&exit", "Exit"
$options = [System.Management.Automation.Host.ChoiceDescription[]]($list, $kill, $exit)
$result = $host.ui.PromptForChoice($title, $message, $options, 0)
switch ($result)
{
0 {listProcesses}
1 {killProcess}
2 {exit}
}
}
Function listProcesses {
#Get-Process -ComputerName $global:ComputerName
Invoke-Command -ComputerName $global:ComputerName -scriptBlock {Get-Process} -credential $global:adminCreds
displayMenu
}
Function killProcess {
$processID = Read-Host 'Process ID?'
Invoke-Command -ComputerName $global:ComputerName -scriptBlock {Stop-Process $args[0] -force} -ArgumentList $processID -credential $global:adminCreds
displayMenu
}
enableWinRM
displayMenu