Posts on this Collection
Earlier than we soar again into Azure, I needed to shortly share a graphic I put collectively. This picture exhibits the variety of website guests I needed to my website on Wednesday, Might 25, 2022. This was the day I revealed the primary put up on this collection, linked above. How encouraging! I had no thought I’d see any customer improve as a result of put up.
I signed up after which signed in to Azure within the UI. Apparently, I had been there earlier than, so it wasn’t actually signing up. I wasn’t utilizing the identical bank card, however as soon as in, I eliminated the older bank card and left the UI for my PowerShell console. I solely seemed on the Azure PowerShell Az.Billing module momentarily, however I’m guessing what I did–eradicating the bank card from my account–couldn’t be accomplished in PowerShell. I’d like to be confirmed fallacious.
Now that that’s accomplished, let’s comply with the Get began with Azure PowerShell doc which begins with making a connection to Azure utilizing the Join-AzAccount
cmdlet. That is the third article of these written by Microsoft. You will have learn the primary two for those who learn my first put up, It Begins – Azure with PowerShell I. Both manner, I’ve linked all three beneath.
Join-AzAccount -OutVariable AzOutput
Once we invoke the above command, to considerably of a shock–possibly–we’re introduced by a webpage from which to sign up.
As soon as the browser-based authentication is full, our PowerShell host updates and gives some host-based output. As you’ll be able to see within the above command, and the beneath picture, we made use of the OutVariable
frequent parameter, with a view to seize any output that isn’t displayed within the host program by default when this command is invoked. Discover, that there’s is not any $
earlier than the variable identify when used with this parameter; PowerShell is aware of it’s a variable and doesn’t want any assist figuring out that.
Let’s discover the brand new variable to see if it holds some other info: Once we enter $AzOutput
into the PowerShell console, it solely returns the 4 above properties we’ve got already seen. So, naturally, let’s attempt extra. Let’s pipe the variable to Choose-Object -Property *
.
$AzOutput | Choose-Object -Property *
Environments Context ------------ ------- {[AzureUSGovernment, AzureUSGovernment], [AzureCloud, AzureCloud], [AzureGermanCloud, AzureGermanCloud], [AzureChinaCloud, AzureChinaCloud]} Microsoft.Azure.Instructions.Profile.Fashions.Core.PSAzureContext
There’s positively extra right here.
Whereas we are inclined to steer clear of the Format-*
cmdlets (as there’s not a lot we will do with the output as soon as it’s been despatched by way of a formatting cmdlet), it made sense on this occasion. We wish a neater method to view the output on the display. We don’t want or need to do something extra with it. Oh! This rule is the format proper rule. Formatting cmdlets, if you want to use them, needs to be on the rightmost of your command(s). The opposite half of the rule is filter left, so in whole, it’s filter left, format proper.
On this instance, it’s a lot simpler for us to see what we’ve got. There are two properties contained in our $AzOutput
variable: Environments and Context.
$AzOutput | Format-Listing -Property *
Environments : {[AzureUSGovernment, AzureUSGovernment], [AzureCloud, AzureCloud], [AzureGermanCloud, AzureGermanCloud], [AzureChinaCloud, AzureChinaCloud]} Context : Microsoft.Azure.Instructions.Profile.Fashions.Core.PSAzureContext
Now. let’s discover every. As soon as accomplished, we’ll see that the Environments property accommodates details about, let’s assume environments. And, the Context property accommodates the properties we noticed earlier on this put up: the Account, the SubscriptionName, and so forth. However we’re not accomplished right here; we’re not about to belief that is it. I’ve been round too lengthy.
$AzOutput.Environments Key Worth --- ----- AzureUSGovernment AzureUSGovernment AzureCloud AzureCloud AzureGermanCloud AzureGermanCloud AzureChinaCloud AzureChinaCloud
$AzOutput.Context
Title Account SubscriptionName Setting TenantId ---- ------- ---------------- ----------- -------- tommymaynard@xxxxxx Free Trial AzureCloud xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
There actually isn’t rather more nested in our Context property, however right here’s a command value operating for those who’re following alongside: $AzOutput.Context | Choose-Object -Property *
to what else is in there.
There’s, nevertheless, an unreal quantity of data on the Environments property. A lot of that is simply expertise. I’m coming to Azure from PowerShell, so these ways and these processes are ingrained in me. I’m not going to indicate you the output of every of the beneath instructions, however I’ll say this, examine your properties, and your properties’ properties, and their properties too, and always remember there could also be extra info that isn’t be displayed. Additionally, perceive what the Get-Member cmdlet does. So it’s been mentioned (though it’s been linked–proper right here and proper now), its job is to return the properties and strategies of PowerShell objects, which is what PowerShell has been designed to return to us by default. So you’ll be able to actually get in there and see what values are saved in an object(s) (properties), and what you are able to do together with your object(s) (strategies), too.
$AzOutput.Environments | Get-Member $AzOutput.Environments.Keys $AzOutput.Environments.Values $AzOutput.Environments.Values | Get-Member $AzOutput.Environments.Values | Choose-Object -Property *
I feel we’ll cease right here for now; I had no thought I’d discover a lot to put in writing about so quickly. I’m not even certain if I actually even bought began. That mentioned, I did discover that there are many different cmdlets within the Az.Accounts PowerShell module. Utilizing the Get-Command
command with the Module parameter, we will see all of them. We are able to additionally view the net assist.
Get-Command -Module Az.Accounts
CommandType Title Model Supply ----------- ---- ------- ------ Alias Add-AzAccount 2.8.0 Az.Accounts Alias Get-AzDomain 2.8.0 Az.Accounts Alias Invoke-AzRest 2.8.0 Az.Accounts Alias Login-AzAccount 2.8.0 Az.Accounts Alias Logout-AzAccount 2.8.0 Az.Accounts Alias Take away-AzAccount 2.8.0 Az.Accounts Alias Resolve-Error 2.8.0 Az.Accounts Alias Save-AzProfile 2.8.0 Az.Accounts Alias Choose-AzSubscription 2.8.0 Az.Accounts Cmdlet Add-AzEnvironment 2.8.0 Az.Accounts Cmdlet Clear-AzConfig 2.8.0 Az.Accounts Cmdlet Clear-AzContext 2.8.0 Az.Accounts Cmdlet Clear-AzDefault 2.8.0 Az.Accounts Cmdlet Join-AzAccount 2.8.0 Az.Accounts Cmdlet Disable-AzContextAutosave 2.8.0 Az.Accounts Cmdlet Disable-AzDataCollection 2.8.0 Az.Accounts Cmdlet Disable-AzureRmAlias 2.8.0 Az.Accounts Cmdlet Disconnect-AzAccount 2.8.0 Az.Accounts Cmdlet Allow-AzContextAutosave 2.8.0 Az.Accounts Cmdlet Allow-AzDataCollection 2.8.0 Az.Accounts Cmdlet Allow-AzureRmAlias 2.8.0 Az.Accounts Cmdlet Get-AzAccessToken 2.8.0 Az.Accounts Cmdlet Get-AzConfig 2.8.0 Az.Accounts Cmdlet Get-AzContext 2.8.0 Az.Accounts Cmdlet Get-AzContextAutosaveSetting 2.8.0 Az.Accounts Cmdlet Get-AzDefault 2.8.0 Az.Accounts Cmdlet Get-AzEnvironment 2.8.0 Az.Accounts Cmdlet Get-AzSubscription 2.8.0 Az.Accounts Cmdlet Get-AzTenant 2.8.0 Az.Accounts Cmdlet Import-AzContext 2.8.0 Az.Accounts Cmdlet Invoke-AzRestMethod 2.8.0 Az.Accounts Cmdlet Open-AzSurveyLink 2.8.0 Az.Accounts Cmdlet Register-AzModule 2.8.0 Az.Accounts Cmdlet Take away-AzContext 2.8.0 Az.Accounts Cmdlet Take away-AzEnvironment 2.8.0 Az.Accounts Cmdlet Rename-AzContext 2.8.0 Az.Accounts Cmdlet Resolve-AzError 2.8.0 Az.Accounts Cmdlet Save-AzContext 2.8.0 Az.Accounts Cmdlet Choose-AzContext 2.8.0 Az.Accounts Cmdlet Ship-Suggestions 2.8.0 Az.Accounts Cmdlet Set-AzContext 2.8.0 Az.Accounts Cmdlet Set-AzDefault 2.8.0 Az.Accounts Cmdlet Set-AzEnvironment 2.8.0 Az.Accounts Cmdlet Uninstall-AzureRm 2.8.0 Az.Accounts Cmdlet Replace-AzConfig 2.8.0 Az.Accounts
Whereas I don’t plan to undergo every, we’ll actually study what we will do with a number of the Get
instructions. Have a look at that. In our above output, we’ve returned Get-AzContext
and Get-AZEnvironment
cmdlets. Attention-grabbing, proper? We’ll come again to this, however I’m guessing all of the work we did exploring our output variable could not have been obligatory; there could also be particular person cmdlets to return that information with out the additional work on our half. We’ll discover out in time, however nonetheless, it was a superb train.
Get-Command -Module Az.Accounts -Verb Get
CommandType Title Model Supply ----------- ---- ------- ------ Alias Get-AzDomain 2.8.0 Az.Accounts Cmdlet Get-AzAccessToken 2.8.0 Az.Accounts Cmdlet Get-AzConfig 2.8.0 Az.Accounts Cmdlet Get-AzContext 2.8.0 Az.Accounts Cmdlet Get-AzContextAutosaveSetting 2.8.0 Az.Accounts Cmdlet Get-AzDefault 2.8.0 Az.Accounts Cmdlet Get-AzEnvironment 2.8.0 Az.Accounts Cmdlet Get-AzSubscription 2.8.0 Az.Accounts Cmdlet Get-AzTenant 2.8.0 Az.Accounts
Right here’s a bit bonus content material earlier than we wrap up. Utilizing the Sort parameter with the Get-Command
cmdlet, we will inform PowerShell to solely return a sure kind of command. On this instance, we return solely the aliases. Once I noticed the total checklist of cmdlets for the primary time, I used to be confused by Login-AzAccount
as we had been utilizing Join-AzAccount
. It seems that Login-AzAccount
is just an alias for Join-AzAccount
.
Get-Command -Module Az.Accounts -Sort Alias
CommandType Title Model Supply ----------- ---- ------- ------ Alias Add-AzAccount 2.8.0 Az.Accounts Alias Get-AzDomain 2.8.0 Az.Accounts Alias Invoke-AzRest 2.8.0 Az.Accounts Alias Login-AzAccount 2.8.0 Az.Accounts Alias Logout-AzAccount 2.8.0 Az.Accounts Alias Take away-AzAccount 2.8.0 Az.Accounts Alias Resolve-Error 2.8.0 Az.Accounts Alias Save-AzProfile 2.8.0 Az.Accounts Alias Choose-AzSubscription 2.8.0 Az.Accounts
Get-Command -Module Az.Accounts -Sort Alias | ForEach-Object {$_ | Choose-Object -Property @{Title="Alias";Expression={$_.DisplayName}},ResolvedCommand}
Alias ResolvedCommand ----- --------------- Add-AzAccount Join-AzAccount Get-AzDomain Get-AzTenant Invoke-AzRest Invoke-AzRestMethod Login-AzAccount Join-AzAccount Logout-AzAccount Disconnect-AzAccount Take away-AzAccount Disconnect-AzAccount Resolve-Error Resolve-AzError Save-AzProfile Save-AzContext Choose-AzSubscription Set-AzContext