PowerShell Genie

Az.Accounts module: setup and commands

Module 2 min read Windows PowerShell 5.1 and PowerShell 7

Documentation: Microsoft Learn

Connect with Connect-AzAccount, inspect subscriptions with Get-AzSubscription and set the intended tenant and subscription context before Azure changes.

Getting it

Install-PSResource -Name Az.Accounts from the PowerShell Gallery, or take the Az meta-module which includes it. Every other Az module lists it as a required dependency.

Examples

1PS> Get-AzContext
Show reference output
1 Name Account SubscriptionName TenantId
2 ---- ------- ---------------- --------
3 Production admin@contoso.com Production aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee
1PS> Get-AzSubscription
Show reference output
1 Name Id State TenantId
2 ---- -- ----- --------
3 Production 11111111-2222-3333-4444-555555555555 Enabled aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee

What it is for

Every Az session begins here, and this is where you land when a resource cmdlet complains that no subscription is selected. It also carries the service principal and managed identity sign-in paths that unattended automation depends on.

Typical tasks

  • Sign in interactively or with a device code
  • Authenticate as a service principal
  • Connect using a managed identity
  • List and switch between subscriptions
  • Save a context for reuse in later sessions
  • Acquire a token for a direct REST call

Check the installed version

1PS> Get-Module -ListAvailable Az.Accounts | Select-Object Name, Version, Path
2PS> Get-Command -Module Az.Accounts

Compare the module path and version with the session used by your scheduled task or automation account. Every Az session begins here, and this is where you land when a resource cmdlet complains that no subscription is selected. It also carries the service principal and managed identity sign-in paths that unattended automation depends on.

Primary documentation

Active Directory PowerShell documentation

Continue
Genie guideAz.Accounts module: setup and commands

Connect with Connect-AzAccount, inspect subscriptions with Get-AzSubscription and set the intended tenant and subscription context before Azure changes.