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
[System.Diagnostics.CodeAnalysis.SuppressMessage('AvoidUsingPlainTextForPassword', '', Target='ProcessParameter')] | |
[CmdletBinding()] | |
param ( | |
[Parameter()] | |
[Alias('SPName','Username','un')] | |
[string] $ServicePrincipalName, | |
[Parameter()] | |
[Alias('SPPassword','Password','pw')] | |
[string] $ServicePrincipalPassword, | |
[Parameter()] | |
[Alias('id')] | |
[string] $TenantId | |
) | |
try { | |
#region Azure Authentication | |
if ((-not $ServicePrincipalName) -or (-not $ServicePrincipalPassword) -or (-not $TenantId)) { | |
Write-Verbose 'Authenticating using interactive login' | |
$loginResult = az login | |
} | |
else { | |
Write-Verbose 'Authenticating with Username and Password' | |
$loginResult = az login --username $ServicePrincipalName --password $ServicePrincipalPassword --tenant $TenantId --service-principal | |
} | |
if ($loginResult) { | |
Write-Output $loginResult | ConvertFrom-Json | |
} | |
#endregion | |
# YOUR CODE GOES HERE | |
} | |
catch { | |
Write-Warning $_.Exception.Message | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment