Last active
April 23, 2021 08:20
-
-
Save gsscoder/a644e64b51b5f7c5b737343a481c6a9a to your computer and use it in GitHub Desktop.
PowerShell function to check Azure CLI version
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Require-AzCliVersion { | |
[OutputType([void])] | |
param( | |
[Parameter(Mandatory, ValueFromPipeline)] [ValidatePattern("^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,9}$")] [string] $Version, | |
[switch] $Fail | |
) | |
$actual = ('az version' | Invoke-Expression | ConvertFrom-Json).'azure-cli' | |
if ($actual -eq $Version) { | |
"Azure CLI present in pinned version $Version" | Write-Verbose | |
} else { | |
$message = "Azure CLI present in version $actual. Pinned version is $Version" | |
if ($Fail) { | |
$message | Write-Error; exit 1 | |
} else { | |
$message | Write-Warning | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment