-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathGet-AzSUpdateStatus.ps1
More file actions
100 lines (88 loc) · 3.37 KB
/
Get-AzSUpdateStatus.ps1
File metadata and controls
100 lines (88 loc) · 3.37 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#1. Send email notification with attachment of CSV file (showing all upgrade activities status and time) in every 3 hours
#2. Send email notification immediately when the upgrade activity hit “error” or “failed” status
<#
Cusotmer need modify info below:
$To = "To-Email-Address"
$CC = "CC-Email-Address"
$SmtpServer = "smtp.gmail.com"
$From = "From-Email-Address"
$port = 587
$ERCS = "xxx.xxx.xx.224"
After customer exports the credential. Customer can remove the first 6 line of the script. Customer can also modify as needed.
#>
$UserName = "From-Email-Address"
$pwd = ConvertTo-SecureString "xxx" -AsPlainText -Force
New-Object System.Management.Automation.PSCredential($UserName, $pwd) | Export-Clixml "C:\temp\FromEmail.xml"
$CloudAdminName = "DomainName\xxx"
$pwd= ConvertTo-SecureString "xxx" -AsPlainText -Force
New-Object System.Management.Automation.PSCredential($CloudAdminName, $pwd) | Export-Clixml "C:\Temp\Cloudadmin.xml"
$CloudAdminCred = Import-Clixml "C:\Temp\Cloudadmin.xml"
$Cred = Import-Clixml "C:\temp\FromEmail.xml"
#$cred = Get-Credential
$To = "To-Email-Address"
$CC = "CC-Email-Address"
$SmtpServer = "smtp.xxx.com"
$From = "From-Email-Address"
$port = 587
$ERCS = "xxx.xxx.xx.xxx"
$updatestatus = Invoke-Command $ERCS -Credential $CloudAdminCred -ConfigurationName PrivilegedEndpoint -ScriptBlock { Get-AzureStackUpdateStatus -statusonly}
$updatestatus.value
while ($updatestatus.Value -eq "Failed")
{
$Verboselog = Invoke-Command $ERCS -Credential $CloudAdminCred -ConfigurationName PrivilegedEndpoint -ScriptBlock { Get-AzureStackUpdateVerboseLog}
$Verboselog > C:\temp\AzSUpdateVerboselog.txt
Send-MailMessage `
-To $To `
-CC $CC `
-Subject "Alert. Update is failed." `
-Body "Update is failed. Attached update verbose log for you, please contact support for help" `
-SmtpServer $SmtpServer `
-From $From `
-Port $port `
-UseSsl `
-Credential $Cred `
-Attachments "C:\temp\AzSUpdateVerboselog.txt"
}
If($updatestatus.Value -eq "Running")
{
$time = Get-Date -format yyyy_MM_ddTHH_mm_ss
[xml]$statusString = Invoke-Command $ERCS -Credential $CloudAdminCred -ConfigurationName PrivilegedEndpoint -ScriptBlock { Get-AzureStackUpdateStatus }
#$statusString.SelectNodes("//Step[@Status='InProgress']") | Export-Csv C:\temp\AzSUpdateStatus$time.CSV
$statusString.SelectNodes("//Step") | Export-Csv C:\temp\AzSUpdateStatus$time.CSV
Send-MailMessage `
-To $To `
-CC $CC `
-Subject "Update is still Running" `
-Body "Update is still Running" `
-SmtpServer $SmtpServer `
-From $From `
-Port $port `
-UseSsl `
-Credential $Cred `
-Attachments "C:\tem\AzSUpdateStatus$time.CSV"
}
elseif ($updatestatus.Value -eq "Completed")
{
Send-MailMessage `
-To $To `
-CC $CC `
-Subject "Update is Completed." `
-Body "Please double confirm Stamp status from Admin Portal" `
-SmtpServer $SmtpServer `
-From $From `
-Port $port `
-UseSsl `
-Credential $Cred
} else
{
Send-MailMessage `
-To $To `
-CC $CC `
-Subject "Something unexpected occurred during AzS upgrade, please check. " `
-Body "Please check Stamp status from Admin Portal" `
-SmtpServer $SmtpServer `
-From $From `
-Port $port `
-UseSsl `
-Credential $Cred
}