Hi all,
Allow me to “pick” your brain a bit?
I want to build a script in order to list all users from a RD farm and “kill” a specific user session. I had something done like this (sorry for the rough scripting):
# Gather the server name $Servers = ('1','2','3','4','5') # find all user IDs using rds $users = @((Invoke-Command -ComputerName $Servers -ScriptBlock {Get-Process *rds* -IncludeUserName | Select-Object -ExpandProperty UserName})) # List out the usernames which are connected and using WON echo $users # Which username to kill $username = Read-Host -Prompt 'Type the username session you wish to kill' foreach ($Server in $Servers) { Invoke-RDUserLogoff -HostServer $Server -UnifiedSessionId $username }
When running the script, the list of users present on the RD farm comes back exactly like I wanted, but when I type in the username I want to “kill” the session, it just comes back:
"Invoke-RDUserLogoff : Cannot process argument transformation on parameter ‘UnifiedSessionID’. Cannot convert value “coelhn01” to type “System.Int32”. Error: “Input string was not in a correct format.”
A little help please?
Thank you so much!
All the best!