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 # Uninstall existing versions of Azure/Azure Stack Hub PowerShell Get-Module -Name Azs.*, Azure* -ListAvailable | Uninstall-Module -Force -Verbose # Install the AzureRM.BootStrapper module. Select Yes when prompted to install NuGet Install-Module -Name AzureRM.BootStrapper -Verbose # Install and import the API Version Profile required by Azure Stack Hub into the current PowerShell session Use-AzureRmProfile -Profile 2019-03-01-hybrid -Force Install-Module -Name AzureStack -RequiredVersion 1.8.1 -Verbose
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 AzureRM environment that targets your Azure Stack Hub instance Add-AzureRmEnvironment -Name "AzureStackUser" -ArmEndpoint $ArmEndpoint # Sign in to your environment Connect-AzureRmAccount -EnvironmentName "AzureStackUser"
Azure Active Directory (AAD) based deployments - Embedded Credentials
# Set Execution Policy Set-ExecutionPolicy -ExecutionPolicy RemoteSigned # Declare endpoint $ArmEndpoint = "" # Register an AzureRM environment that targets your Azure Stack Hub instance Add-AzureRmEnvironment -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-AzureRmAccount -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-AzureRmLocation).Location New-AzureRmResourceGroup -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.