forked from amolmehrotra/Azure-Stack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGetAzureStackUpdateStatus.ps1
More file actions
56 lines (49 loc) · 1.95 KB
/
GetAzureStackUpdateStatus.ps1
File metadata and controls
56 lines (49 loc) · 1.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#Create a PEP session
$cred = get-credential
$pepsession = New-PSSession -ComputerName 172.160.169.224 -ConfigurationName PrivilegedEndpoint -Credential $cred
$ScriptBlock = {
$duration=""
[DateTime]$endTime = Get-Date
if (![String]::IsNullOrEmpty($_.StartTimeUtc)){
if (![String]::IsNullOrEmpty($_.EndTimeUtc)){
$endTime = $_.EndTimeUtc
}
$duration= ($endTime - [DateTime]$_.StartTimeUtc).ToString("hh\:mm\:ss")
}
Write-Host ("{0,-8} {1,-10} {2,-30} {3,-20} {4}" -f $_.FullStepIndex,$duration,$_.Name,$_.Status,$_.Description)
}
$failed = $false
Write-Host -ForegroundColor Cyan "Checking update run progress"
try
{
[xml]$status = Invoke-Command -Session $pepsession -ScriptBlock {Get-AzureStackUpdateStatus}
switch ($status.Action.Status)
{
'Unknown' {
Write-Host -ForegroundColor Cyan "Update run state is unknown" }
'Succeeded' {
Write-Host -ForegroundColor Green "Update run is successful" }
'InProgress' {
Write-Host -ForegroundColor Cyan "Update run is in progress" }
'Failed' {
Write-Host -ForegroundColor Yellow "Update run failed"
$failed = $true
return }
}
$runtime = (Get-Date) - $([DateTime]$status.Action.StartTimeUtc)
#$status.SelectNodes("//Step") | % $ScriptBlock
$status.SelectNodes("//Step") | Where-Object {$_.Status -notlike "Success"} | % $ScriptBlock
}
catch
{
Write-Host -ForegroundColor Yellow "Exception - ERCS may be unavailable"
}
Finally
{
if ($status.Action.Status -eq 'InProgress' -and (-NOT $failed))
{
$time = Get-Date -Format s
Write-Host -ForegroundColor Cyan "$time - Current Run Time: $($runtime) - Sleeping $retryDelay seconds"
Start-Sleep -Seconds $retryDelay
}
}