Skip to content

Instantly share code, notes, and snippets.

@gsscoder
Last active April 23, 2021 08:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gsscoder/a644e64b51b5f7c5b737343a481c6a9a to your computer and use it in GitHub Desktop.
Save gsscoder/a644e64b51b5f7c5b737343a481c6a9a to your computer and use it in GitHub Desktop.
PowerShell function to check Azure CLI version
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