Azure PowerShell
Introduction
Section titled “Introduction”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.
Getting started
Section titled “Getting started”Prerequisites
Section titled “Prerequisites”- PowerShell 7.
- The
Az.AccountsandAz.Resourcesmodules. - LocalStack for Azure, with the emulator running. For more information, see Installation.
Install-Module -Name Az.Accounts -Scope CurrentUser -ForceInstall-Module -Name Az.Resources -Scope CurrentUser -ForceConfigure the session
Section titled “Configure the session”Run the following commands first:
Disable-AzContextAutosave -Scope ProcessUpdate-AzConfig -DisableInstanceDiscovery $true -Scope ProcessBoth settings apply only to the current PowerShell session, so your saved Azure sign-ins and settings stay as they are:
Disable-AzContextAutosavestops Azure PowerShell from saving the emulator’s sign-in as your default Azure context.DisableInstanceDiscoverystops theAzmodules from asking Microsoft Entra ID to validate the emulator’s sign-in endpoint, which Microsoft Entra ID doesn’t know.Update-AzConfigprints a warning that the setting also turns off authority validation. That’s expected.
Sign in
Section titled “Sign in”The emulator accepts any service principal:
$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"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-000000000000The warning is harmless: the sign-in succeeds, and the following cmdlets work. For more information about the values that the emulator accepts, see Credentials.
Manage resources
Section titled “Manage resources”Create a resource group:
New-AzResourceGroup -Name MyResourceGroup -Location westeuropeResourceGroupName : MyResourceGroupLocation : westeuropeProvisioningState : SucceededTags :ResourceId : /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/MyResourceGroupShow it:
Get-AzResourceGroup -Name MyResourceGroup | Select-Object ResourceGroupName, Location, ProvisioningStateResourceGroupName Location ProvisioningState----------------- -------- -----------------MyResourceGroup westeurope SucceededAzure 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:
Remove-AzResourceGroup -Name MyResourceGroup -ForceTrueClean up
Section titled “Clean up”Sign out and remove the environment:
Disconnect-AzAccountRemove-AzEnvironment -Name LocalStackThe 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 stillFalsein this session. - Cmdlets work for the services and operations that the emulator implements. For the list, see Local Azure Services.