Created
June 13, 2017 08:36
-
-
Save gravejester/0f129b108b23add5dcb2fe2dde92e994 to your computer and use it in GitHub Desktop.
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