Use Docker to run PowerShell in Azure Stack
In this article, you use Docker to create Windows-based containers on which to run the version of PowerShell that's required for working with the various interfaces. In Docker, you must use Windows-based containers.
In a command-line program, such as Powershell or Bash, enter:
You need to run Docker by using Windows containers that require Windows 10. When you run Docker, switch to Windows containers.
Run Docker from a machine that's joined to the same domain as Azure Stack. If you are using the Azure Stack Development Kit (ASDK), you need to install the VPN on your remote machine.
Set up a service principal for using PowerShell
To use PowerShell to access resources in Azure Stack, you need a service principal in your Azure Active Directory (Azure AD) tenant. You delegate permissions with user role-based access control (RBAC).
To set up your service principal, follow the instructions in Give applications access to Azure Stack resources by creating service principals.
Note the application ID, the secret, and your tenant ID for later use.
Docker - Azure Stack API profiles module
The Dockerfile opens the Microsoft image microsoft/windowsservercore, which has Windows PowerShell 5.1 installed. The file then loads NuGet and the Azure Stack PowerShell modules, and downloads the tools from Azure Stack Tools.
Download the azure-stack-powershell repository as a ZIP file, or clone the repository.
Open the repository folder from your terminal.
Open a command-line interface in your repository, and then enter the following command:
docker build --tag azure-stack-powershell .
When the image has been built, start an interactive container by entering:
docker run -it azure-stack-powershell powershell
The shell is ready for your cmdlets.
Windows PowerShell Copyright (C) 2016 Microsoft Corporation. All rights reserved. PS C:\>
Connect to your Azure Stack instance by using the service principal. You are now using a PowerShell prompt in Docker.
$passwd = ConvertTo-SecureString <Secret> -AsPlainText -Force $pscredential = New-Object System.Management.Automation.PSCredential('<ApplicationID>', $passwd) Connect-AzureRmAccount -ServicePrincipal -Credential $pscredential -TenantId <TenantID>
PowerShell returns your account object:
Account SubscriptionName TenantId Environment ------- ---------------- -------- ----------- <AccountID> <SubName> <TenantID> AzureCloud
Test your connectivity by creating a resource group in Azure Stack.
New-AzureRmResourceGroup -Name "MyResourceGroup" -Location "Local"