Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $Timeout = 30
- $RetryInterval = 3
- $wmi = $null
- try
- {
- $timer = [Diagnostics.Stopwatch]::StartNew()
- while (($timer.Elapsed.TotalSeconds -lt $Timeout) -and ($wmi =Get-WmiObject -ComputerName $Server -Namespace root\cimv2 -class Win32_OperatingSystem)) {
- Start-Sleep -Seconds $RetryInterval
- $totalSecs = [math]::Round($timer.Elapsed.TotalSeconds,0)
- Write-Verbose -Message "Still waiting for action to complete after [$totalSecs] seconds..."
- }
- $timer.Stop()
- if ($timer.Elapsed.TotalSeconds -gt $Timeout -and ($wmi -eq $null)) {
- throw 'Action did not complete before timeout period.'
- } else {
- Write-Verbose -Message 'Action completed before timeout period.'
- }
- }
- catch
- {
- Write-Error -Message $_.Exception.Message
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement