Configure the Azure Stack user's PowerShell environment

Applies to: Azure Stack integrated systems and Azure Stack Development Kit

Use the instructions in this article to configure the PowerShell environment for an Azure Stack user. After you configure the environment, you can use PowerShell to manage Azure Stack resources. For example, you can use PowerShell to subscribe to offers, create virtual machines, and deploy Azure Resource Manager templates.

Note

This article is scoped for Azure Stack user environments. If you want to set up PowerShell for the cloud operator environment, refer to the Configure the Azure Stack operator's PowerShell environment article.

Prerequisites

You can configure these prerequisites from the development kit, or from a Windows-based external client if you are connected through VPN:

Configure the user environment and sign in to Azure Stack

Based on the type of your Azure Stack deployment (Azure AD or AD FS), run one of the following scripts to configure PowerShell for Azure Stack.

Make sure you replace the following script variables with values from your Azure Stack configuration:

  • AAD tenantName
  • GraphAudience endpoint
  • ArmEndpoint

Azure Active Directory (AAD) based deployments

# Navigate to the downloaded folder and import the **Connect** PowerShell module
Set-ExecutionPolicy RemoteSigned
Import-Module .\Connect\AzureStack.Connect.psm1

# For Azure Stack development kit, this value is set to https://management.local.azurestack.external. To get this value for Azure Stack integrated systems, contact your service provider.
$ArmEndpoint = "<Resource Manager endpoint for your environment>"

# For Azure Stack development kit, this value is set to https://graph.windows.net/. To get this value for Azure Stack integrated systems, contact your service provider.
$GraphAudience = "<GraphAudience endpoint for your environment>"

# Register an AzureRM environment that targets your Azure Stack instance
Add-AzureRMEnvironment `
  -Name "AzureStackUser" `
  -ArmEndpoint $ArmEndpoint

# Set the GraphEndpointResourceId value
Set-AzureRmEnvironment `
  -Name "AzureStackUser" `
  -GraphAudience $GraphAudience

# Get the Active Directory tenantId that is used to deploy Azure Stack
$TenantID = Get-AzsDirectoryTenantId `
  -AADTenantName "<myDirectoryTenantName>.onmicrosoft.com" `
  -EnvironmentName "AzureStackUser"

# Sign in to your environment
Login-AzureRmAccount `
  -EnvironmentName "AzureStackUser" `
  -TenantId $TenantID

Active Directory Federation Services (AD FS) based deployments

# Navigate to the downloaded folder and import the **Connect** PowerShell module
Set-ExecutionPolicy RemoteSigned
Import-Module .\Connect\AzureStack.Connect.psm1

# For Azure Stack development kit, this value is set to https://management.local.azurestack.external. To get this value for Azure Stack integrated systems, contact your service provider.
$ArmEndpoint = "<Resource Manager endpoint for your environment>"

# For Azure Stack development kit, this value is set to https://graph.local.azurestack.external/. To get this value for Azure Stack integrated systems, contact your service provider.
$GraphAudience = "<GraphAudience endpoint for your environment>"

# Register an AzureRM environment that targets your Azure Stack instance
Add-AzureRMEnvironment `
  -Name "AzureStackUser" `
  -ArmEndpoint $ArmEndpoint

# Set the GraphEndpointResourceId value
Set-AzureRmEnvironment `
  -Name "AzureStackUser" `
  -GraphAudience $GraphAudience `
  -EnableAdfsAuthentication:$true

# Get the Active Directory tenantId that is used to deploy Azure Stack
$TenantID = Get-AzsDirectoryTenantId `
  -ADFS `
  -EnvironmentName "AzureStackUser"

# Sign in to your environment
Login-AzureRmAccount `
  -EnvironmentName "AzureStackUser" `
  -TenantId $TenantID

Register resource providers

Resource providers aren’t automatically registered for new user subscriptions that don’t have any resources deployed through the portal. You can explicitly register a resource provider by running the following script:

foreach($s in (Get-AzureRmSubscription)) {
        Select-AzureRmSubscription -SubscriptionId $s.SubscriptionId | Out-Null
        Write-Progress $($s.SubscriptionId + " : " + $s.SubscriptionName)
Get-AzureRmResourceProvider -ListAvailable | Register-AzureRmResourceProvider -Force
    }

Test the connectivity

When you've got everything set up, test connectivity by using PowerShell to create resources in Azure Stack. As a test, create a resource group for an application and add a virtual machine. Run the following command to create a resource group named "MyResourceGroup":

New-AzureRmResourceGroup -Name "MyResourceGroup" -Location "Local"

Next steps