With Remote Desktop Services (RDS) in sever 2012 there is no ability to shadow a user's session. This is supposed to come back in R2, but for now I wanted a quick way to kill a process for a user on a RDS host session. As you all know, sometimes programs lock up and users call needing the program "unfroozen". When using a RDS host farm and connection broker it can prove difficult to "get your hands" on the user's session. After some Get-Help and research on google I made this script and I thought I would share. I am open for suggestions on improvements as well.
Basically what is going on here is that I am prompting the admin to input the remote computer name, the process, and the user. Then the script finds that process and kills it for that user. I am just starting on my journey to PowerShell guru status so I welcome any constructive criticism. Thanks and enjoy...
$remotecomputer = Read-Host "Enter Computer Name" $process_name = Read-Host "Enter Process Name example:notepad.exe" $user = Read-Host "Enter username to terminate the process for" Get-WmiObject -Class Win32_Process -Filter "Name= '$process_name'" -ComputerName $remotecomputer | Where-Object { $_.GetOwner().User -eq $user } | Foreach-Object { $_.Terminate() }