Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
[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