-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Open
Labels
Azure CLI TeamThe command of the issue is owned by Azure CLI teamThe command of the issue is owned by Azure CLI teamcustomer-reportedIssues that are reported by GitHub users external to the Azure organization.Issues that are reported by GitHub users external to the Azure organization.questionThe issue doesn't require a change to the product in order to be resolved. Most issues start as thatThe issue doesn't require a change to the product in order to be resolved. Most issues start as that
Milestone
Description
function Invoke-AzureCommand {
param (
[string]$Command
)
$azargs = @($Command -split " ")
try {
$stdout = @()
$stderr = @()
& "C:\Program Files\Microsoft SDKs\Azure\CLI2\python.exe" -IBm azure.cli $azargs 2>&1 | ForEach-Object {
if ($_ -is [System.Management.Automation.ErrorRecord]) {
$stderr += $_
}
else {
$stdout += $_
}
}
if ($stderr.Count -gt 0 -and $stdout.Count -eq 0) {
throw ($stderr -join "`n")
}
return $stdout
}
catch {
Write-Error "Azure CLI Error: $($_.Exception.Message)"
}
}
Use like Invoke-AzureCommand -Command "account list"
With this you can work with try-catch in powershell for automatization.
Metadata
Metadata
Assignees
Labels
Azure CLI TeamThe command of the issue is owned by Azure CLI teamThe command of the issue is owned by Azure CLI teamcustomer-reportedIssues that are reported by GitHub users external to the Azure organization.Issues that are reported by GitHub users external to the Azure organization.questionThe issue doesn't require a change to the product in order to be resolved. Most issues start as thatThe issue doesn't require a change to the product in order to be resolved. Most issues start as that