How to configure the Azure Stack Hub user's PowerShell environment
As an Azure Stack Hub user, 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 user 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 endpoint for Azure Stack Hub|
|$AzsUsername||Your AAD username|
|$AzsPassword||Your AAD password|
Install Azure Stack Hub PowerShell
# Set Execution Policy Set-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 # 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 -AllowPrerelease # Install and import the API Version Profile required by Azure Stack Hub into the current PowerShell session Install-AzProfile -Profile 2019-03-01-hybrid -Force Install-Module -Name AzureStack -RequiredVersion 2.0.2-preview -AllowPrerelease # Confirm the installation Get-Module -Name "Az*" -ListAvailable Get-Module -Name "Azs*" -ListAvailable
Configure the user environment and sign in to Azure Stack Hub
Azure Active Directory (AAD) based deployments
# Set Execution Policy Set-ExecutionPolicy RemoteSigned # Declare endpoint $ArmEndpoint = "" # Register an Az environment that targets your Azure Stack Hub instance Add-AzEnvironment -Name "AzureStackUser" -ArmEndpoint $ArmEndpoint # Sign in to your environment Connect-AzAccount -EnvironmentName "AzureStackUser"
Azure Active Directory (AAD) based deployments - Embedded Credentials
# Set Execution Policy Set-ExecutionPolicy -ExecutionPolicy RemoteSigned # Declare endpoint $ArmEndpoint = "" # Register an Az environment that targets your Azure Stack Hub instance Add-AzEnvironment -Name "AzureStackUser" -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 "AzureStackUser"
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 firstname.lastname@example.org.