Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

Powershell hangs and no response

$
0
0

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


Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>