How to configure the Azure Stack Hub operator's PowerShell environment
As an Azure Stack Hub operator, you can use PowerShell to manage Azure Stack Hub resources such as create virtual machines, deploy Azure Resource Manager templates, etc. This topic is scoped to use with the operator environments only. In order to interact with Azure Stack Hub PowerShell you will need to set up your environment. To do so follow the below guide:
Prerequisites from a Windows-based external client.
To check your version, run
$PSVersionTable.PSVersionand compare the "Major" version.
For "legacy" operating systems such as Windows Server 2008 R2, Windows 7, Windows Server 2012, Windows Server 2012 R2 and Windows 8.1 you will need to download the Windows Management Framework 5.1
Enter details below to provide values for the variables in the scripts in this article:
|Variable name||Variable description||Input|
|$ArmEndpoint||The Azure Resource Manager admin endpoint for Azure Stack Hub|
|$AzsUsername||Your AAD username|
|$AzsPassword||Your AAD password|
Install Azure Stack Hub PowerShell
# Set Execution Policy Set-ExecutionPolicy -ExecutionPolicy RemoteSigned # PowerShell commands for Azure Stack Hub are installed through the PSGallery repository # To register the PSGallery repository, open an elevated PowerShell session and run the following command: Set-PSRepository -Name "PSGallery" -InstallationPolicy Trusted # Install the latest version of PowerShellGet Install-Module -Name PowerShellGet -Force
Close and reopen your elevated PowerShell session to load the newly installed version of the PowerShellGet module.
# Uninstall existing versions of Azure/Azure Stack Hub PowerShell Get-Module -Name Azs.*, Azure*, Az.* -ListAvailable | Uninstall-Module -Force -Verbose # On some older systems, you may need to explicitly set the TLS 1.2 security protocol to be able to interact with PowerShell Gallery [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 # Install the Az.BootStrapper module Install-Module -Name Az.BootStrapper -Force # Install and import the API Version Profile required by Azure Stack Hub into the current PowerShell session Install-AzProfile -Profile 2020-09-01-hybrid -Force Install-Module -Name AzureStack -RequiredVersion 2.2.0 # Confirm the installation Get-Module -Name "Az*" -ListAvailable Get-Module -Name "Azs*" -ListAvailable
Configure the operator environment and sign in to Azure Stack Hub
Azure Active Directory (AAD) based deployments
# Set Execution Policy Set-ExecutionPolicy -ExecutionPolicy RemoteSigned # Declare endpoint $ArmEndpoint = "" # Register an Az environment that targets your Azure Stack Hub instance Add-AzEnvironment -Name "AzureStackAdmin" -ArmEndpoint $ArmEndpoint # Sign in to your environment Connect-AzAccount -EnvironmentName "AzureStackAdmin"
Azure Active Directory (AAD) based deployments - Embedded Credentials
This method will not work if multi-factor authentication is required for your AAD account. You must use the other method that does not have the -Credential parameter on the Connect-AzAccount cmdlet.
# Set Execution Policy Set-ExecutionPolicy -ExecutionPolicy RemoteSigned # Declare endpoint $ArmEndpoint = "" # Register an Az environment that targets your Azure Stack Hub instance Add-AzEnvironment -Name "AzureStackAdmin" -ArmEndpoint $ArmEndpoint # Create your Credentials $AzsUsername = "" $AzsPassword = '' $AzsUserPassword = ConvertTo-SecureString -String $AzsPassword -AsPlainText -Force $AzsCred = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $AzsUsername, $AzsUserPassword # Sign in to your environment Connect-AzAccount -Credential $AzsCred -EnvironmentName "AzureStackAdmin"
Test the connectivity
Now that we've got everything set-up, let's use PowerShell to create resources within Azure Stack Hub. For example, you can create a resource group for an application and add a virtual machine. Use the following command to create a resource group named "MyResourceGroup":
# Get location of Azure Stack Hub $Location = (Get-AzLocation).Location New-AzResourceGroup -Name "MyResourceGroup" -Location $Location
If you find a problem with this article, click Improve this Doc to make the change yourself or raise an issue in GitHub. If you have an idea for how we could improve any of our services, send an email to email@example.com.