Last active
October 4, 2018 21:56
-
-
Save ljtill/9afa160ae39f22d174d711aadb3f787e to your computer and use it in GitHub Desktop.
Provides the ability to validate the current session context
This file contains hidden or 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
| 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