none
Powershell hangs and no response RRS feed

  • Question

  • 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

    Saturday, April 11, 2015 4:36 PM

Answers

  • Your scrip[t makes no sense.  What is it that you are trying to do?  You have asked many questions and none are consistent.  This makes understanding what you are asking nearly impossible.  I have asked you to run a transcript on your original issue to se which servers are hung.  You have not done that.  I do not see how it is possible to help you.


    \_(ツ)_/

    Monday, April 13, 2015 10:52 PM

All replies

  • Not enough information.  It Test-Connection succeeds then you need to fix the terminal server.

    What have you done to determine which call it hangs on?  Perhaps you should run a transcript to see where you are hanging.

    help transcript

    Follow instructions.


    \_(ツ)_/

    Saturday, April 11, 2015 5:33 PM
  • Hi Jrv,

    The servers are Citrix servers and hangs more often and the only way to recover the servers is to reboot it using ILO. What i am trying here is to find the hung servers using the script and reboot it. The scrpit hangs when we use GET-TSSession or qwinsta, below is where it hangs.

    PS C:\Users\test> Get-TSSession -Computername testserver -Verbose
    VERBOSE: [Get-TSSession] Entering Begin block.
    VERBOSE: [Get-TSSession] Attempting remote connection to 'testserver'
    VERBOSE: [Get-TSSession] Connection is open 'testserver'
    VERBOSE: [Get-TSSession] Updating global Server name 'testserver'
    VERBOSE: [Get-TSSession] Entering Process block.
    VERBOSE: [Get-TSSession] Binding to ParameterSetName 'Session'

    Saturday, April 11, 2015 9:44 PM
  • And what is the qu4estion?  Did you run transcript as suggested. It will tell you which server is failing.


    \_(ツ)_/

    • Proposed as answer by jrv Sunday, April 12, 2015 6:03 AM
    • Unproposed as answer by jrv Sunday, April 12, 2015 6:03 AM
    • Proposed as answer by jrv Sunday, April 12, 2015 6:03 AM
    • Unproposed as answer by jrv Sunday, April 12, 2015 6:03 AM
    • Proposed as answer by jrv Sunday, April 12, 2015 6:03 AM
    Saturday, April 11, 2015 11:24 PM
  • Hi Jrv,

    I want to find all those hung servers using the script.That is what i am trying to do and the script is not timing out and hangs when it hits the bad server. I also tried the below method and still the result is same.Can you please assist.

    $timeoutSeconds = 3
    $code = {
        # your commands here, e.g.
        Get-ChildItem *.cs | select name
    }
    $j = Start-Job -ScriptBlock $code
    if (Wait-Job $j -Timeout $timeoutSeconds) { Receive-Job $j }
    Remove-Job -force $j


    Sunday, April 12, 2015 5:59 AM
  • Can some one assist me here.
    Monday, April 13, 2015 3:58 PM
  • Can some one assist me here.

    Please run a transcript of the session and post it.

    \_(ツ)_/

    Monday, April 13, 2015 5:35 PM
  • Hi Jrv,

    I managed write a new script on my own using start-job and works fine but it returns false results at times. Not sure if i am using the Job cmdlets correctly.Could you please check and advise if anything is wrong in my script.

    What i did in the script is if the start-job still exist after 10 seconds then that server is set as hung server.however some time even if the start-job exits within seconds, it has a qwinsta process running in the background and it is reporting as hung server.

    $hungservers = @()
    $workingservers = @()
    $servers = get-xaserver -WorkerGroupName 'test'
    $timeoutSeconds = 10
    foreach ($server in $servers)
    {
    If (Test-Connection -ComputerName $server -Count 1 -quiet) {
        get-process -Name qwinsta -ErrorAction silentlycontinue|Stop-Process
        $code = { param($server)
        start-process qwinsta "/server:$server" -wait -windowstyle hidden
        }

        $job = Start-Job -ScriptBlock $code -Arg $Server
        if (Wait-Job $job -Timeout $timeoutSeconds) { Receive-Job $job -ErrorAction silentlycontinue}
        $process = Get-Process -Name qwinsta -ErrorAction silentlycontinue
        $process
        Remove-Job -force $job
        get-process -Name qwinsta -ErrorAction silentlycontinue|Stop-Process

    if ($process) {
        Write-Host $server is hung -ForeGroundColor Yellow
        Set-XAServerLogOnMode -ServerName $server -LogOnMode ProhibitNewLogOnsUntilRestart
        $hungservers += $server
        }
    else {
        Write-Host $server -ForeGroundColor Green
        $workingservers += $Server
        }
    }
    else
        {
        Write-Host $server is not reachable
        }
    }

    Monday, April 13, 2015 10:32 PM
  • Your scrip[t makes no sense.  What is it that you are trying to do?  You have asked many questions and none are consistent.  This makes understanding what you are asking nearly impossible.  I have asked you to run a transcript on your original issue to se which servers are hung.  You have not done that.  I do not see how it is possible to help you.


    \_(ツ)_/

    Monday, April 13, 2015 10:52 PM