Skip to content

Instantly share code, notes, and snippets.

@ljtill
Last active October 4, 2018 21:56
Show Gist options
  • Select an option

  • Save ljtill/9afa160ae39f22d174d711aadb3f787e to your computer and use it in GitHub Desktop.

Select an option

Save ljtill/9afa160ae39f22d174d711aadb3f787e to your computer and use it in GitHub Desktop.
Provides the ability to validate the current session context
function Get-AzureRmContext {
<#
.SYNOPSIS
Get-AzureRmContext will validate the current AzureRm session.
.DESCRIPTION
Validates that the current session is authenticated, if not then it will initiate Add-AzureRmAccount.
.EXAMPLE
Get-AzureRmContext
#>
[CmdletBinding()]
param (
)
begin {
Write-Verbose -Message "Initiating function 'Get-AzureRmContext'."
}
process {
try {
$Context = Get-AzureRmContext
if ($Context.Account -eq $null) {
Add-AzureRmAccount | Out-Null
}
}
catch {
Write-Verbose -Message "Initiating function 'Get-AzureRmContext' failed."
Write-Exception $_.Exception.Message
break
}
}
end {
Write-Verbose -Message "Initiating function 'Get-AzureRmContext' completed."
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment