For Example:
.\Ping-alive.ps1 Server1
DOWN:..TS UP....TS UP........8:00PM
PING:......8:02PM
SVC:................................Server1 8:08PM
<# .SYNOPSIS Report when can RDP into server after Reboot. .DESCRIPTION Pings server until available, then does a WMI call until Remote Desktop service is running.. .PARAMETER Identity Servername to check. .EXAMPLE .\Ping-Alive.ps1 -identity SERVER1 #> [CmdLetBinding()] param( [parameter(Position=0,Mandatory=$true,ValueFromPipelineByPropertyName=$true,HelpMessage="Servername to watch")] [string]$Identity ) $TSDown = $false write-host "DOWN:" -NoNewline do { $test = Test-Connection -ComputerName $identity -Quiet if (!$TSDown) { $TSDown = (gwmi win32_service -ComputerName $identity -filter "state = 'running' and name = 'TermService' " -erroraction silentlycontinue) -eq $null if (!$TSDown) { Write-Host "..TS UP.." -NoNewline } } Write-Host "." -NoNewline } while ($test) Write-Host (get-date).toshorttimestring() write-host "PING:" -NoNewline do { $test = Test-Connection -ComputerName $identity -Quiet Write-Host "." -NoNewline } while (!$test) if ($test) {Write-Host (get-date).toshorttimestring()} Write-Host "SVC:" -NoNewline Do { $testname = (gwmi win32_service -ErrorAction SilentlyContinue -ComputerName $identity -filter "state = 'running' and name = 'TermService' ") -ne $null Write-Host "." -NoNewline Start-Sleep -Milliseconds 500 } while (!$testname) if ($testname) {Write-Host $identity,(get-date).toshorttimestring()}
No comments:
Post a Comment