Skip to content

Commit

Permalink
Implement fix to Suppress Warning Messages regarding AzureRM modules
Browse files Browse the repository at this point in the history
  • Loading branch information
diecknet authored Sep 21, 2023
1 parent 556b6ce commit 0bc0249
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion SimpleAzureVMStartStop.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,13 @@ param(

Write-Output "Script started at $(Get-Date -Format 'yyyy-MM-dd HH:mm:ss')"

# temporarily hide Warning message (see Issue #2 in Github)
$WarningPreference = "SilentlyContinue"
# explicitly load the required PowerShell Az modules
Import-Module Az.Accounts,Az.Compute
# re-set WarningPreference to show Warning Messages
$WarningPreference = "Continue"

$errorCount = 0

# connect to Azure, suppress output
Expand Down Expand Up @@ -179,4 +186,4 @@ $endOfScriptText = "Script ended at $(Get-Date -Format 'yyyy-MM-dd HH:mm:ss')"
if ($errorCount -gt 0) {
throw "Errors occured: $errorCount `r`n$endofScriptText"
}
Write-Output $endOfScriptText
Write-Output $endOfScriptText

0 comments on commit 0bc0249

Please sign in to comment.