Skip to content

Instantly share code, notes, and snippets.

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