The below script works fine if the servers are performing normal but hangs when the server is non responsive. I need the script to timeout if no response and get me the list of servers that are non responsive.Please assist.
$timeoutSeconds = 30
Import-Module psterminalservices -Erroraction SilentlyContinue
Add-PsSnapin Citrix* -Erroraction SilentlyContinue
$servers = get-xaserver
Function Get-ProcessName {
foreach ($server in $servers)
{
If (Test-Connection -ComputerName $server -Count 1 -quiet) {
Write-Host Checking Sessions on Server $Server
$sessions = Get-TSSession -Computername $Server -State down|Get-TSProcess |? {$_.SecurityIdentifier -ne "S-1-5-18"}
foreach ($session in $Sessions)
{
$props = @{
ServerName=$server
ProcessName = $Session.ProcessName
ProcessID = $Session.ProcessID
SessionID = $Session.SessionID
}
New-Object PsObject -Property $props
#Write-Host $Props.Processname `t $Props.ProcessID, `t $Props.SessionID `t $Props.ServerName
tskill $props.processid /Server:$server /V
}}}}
get-processname