Skip to content
Get Started for Free

Azure PowerShell

Azure PowerShell is a set of PowerShell modules, the Az modules, for managing Azure resources. It reaches the LocalStack Azure emulator through a custom Azure environment that you register with Add-AzEnvironment.

  • PowerShell 7.
  • The Az.Accounts and Az.Resources modules.
  • LocalStack for Azure, with the emulator running. For more information, see Installation.
Terminal window
Install-Module -Name Az.Accounts -Scope CurrentUser -Force
Install-Module -Name Az.Resources -Scope CurrentUser -Force

Run the following commands first:

Terminal window
Disable-AzContextAutosave -Scope Process
Update-AzConfig -DisableInstanceDiscovery $true -Scope Process

Both settings apply only to the current PowerShell session, so your saved Azure sign-ins and settings stay as they are:

  • Disable-AzContextAutosave stops Azure PowerShell from saving the emulator’s sign-in as your default Azure context.
  • DisableInstanceDiscovery stops the Az modules from asking Microsoft Entra ID to validate the emulator’s sign-in endpoint, which Microsoft Entra ID doesn’t know. Update-AzConfig prints a warning that the setting also turns off authority validation. That’s expected.

The emulator accepts any service principal:

Terminal window
$sec = ConvertTo-SecureString "dummy" -AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential("any-app", $sec)
Connect-AzAccount -Environment LocalStack -ServicePrincipal -Credential $cred `
-Tenant "00000000-0000-0000-0000-000000000000"
Output
WARNING: Unable to acquire token for tenant '' with error 'Tenant id cannot be null. You can locate your tenant id by following the instructions listed here: https://learn.microsoft.com/partner-center/find-ids-and-domain-names (Parameter 'tenantId')'
Subscription name Tenant
----------------- ------
Emulated Azure Subscription by LocalStack 00000000-0000-0000-0000-000000000000

The warning is harmless: the sign-in succeeds, and the following cmdlets work. For more information about the values that the emulator accepts, see Credentials.

Create a resource group:

Terminal window
New-AzResourceGroup -Name MyResourceGroup -Location westeurope
Output
ResourceGroupName : MyResourceGroup
Location : westeurope
ProvisioningState : Succeeded
Tags :
ResourceId : /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/MyResourceGroup

Show it:

Terminal window
Get-AzResourceGroup -Name MyResourceGroup | Select-Object ResourceGroupName, Location, ProvisioningState
Output
ResourceGroupName Location ProvisioningState
----------------- -------- -----------------
MyResourceGroup westeurope Succeeded

Azure PowerShell and the Azure CLI talk to the same emulator, so each tool sees the resources that the other creates. To check with the Azure CLI, run lstk az start-interception, then az group list --output table.

Delete the resource group:

Terminal window
Remove-AzResourceGroup -Name MyResourceGroup -Force
Output
True

Sign out and remove the environment:

Terminal window
Disconnect-AzAccount
Remove-AzEnvironment -Name LocalStack

The session settings end when you close PowerShell.

  • If a cmdlet seems to hang, run Get-AzConfig -DisableInstanceDiscovery. A pause of several minutes means that the setting is still False in this session.
  • Cmdlets work for the services and operations that the emulator implements. For the list, see Local Azure Services.
Was this page helpful?