Installing PowerShell for Azure Stack has a number of prerequistes which need to be met. The following script has been designed and tested to preform all the necessary tasks within a single script execution.
The following steps have been taken from https://docs.microsoft.com/en-us/azure/azure-stack/azure-stack-powershell-install
1. Verify your prerequisites
Before your get started with Azure Stack and PowerShell, you will need to have a few requirements in place.
PowerShell Version 5.0
To check your version, run $PSVersionTable.PSVersion and compare the Major version. If you do not have PowerShell 5.0, follow the link to upgrade to PowerShell 5.0.
Note
PowerShell 5.0 requires a Windows machine.
Run Powershell an elevated prompt
You will need to be able to run PowerShell with administrative privileges.
PowerShell Gallery access
You will need access to the PowerShell Gallery. The gallery is the central repository for PowerShell content. The PowerShellGet module contains cmdlets for discovering, installing, updating, and publishing PowerShell artifacts such as modules, DSC resources, role capabilities, and scripts from the PowerShell Gallery and other private repositories. If you are using PowerShell in a disconnected scenario, you will need to retrieve resources from a machine with a connection to the Internet and store them in a location accessible to your disconnected machine.
2. Validate if the PowerShell Gallery is accessible
Validate if PSGallery is registered as a repository.
Note
This step requires Internet access.
Open an elevated PowerShell prompt, and run the following cmdlets:
PowerShell
Import-Module -Name PowerShellGet -ErrorAction Stop
Import-Module -Name PackageManagement -ErrorAction Stop
Get-PSRepository -Name “PSGallery”
If the repository is not registered, open an elevated PowerShell session and run the following command:
PowerShell
Register-PsRepository -Default
Set-PSRepository -Name “PSGallery” -InstallationPolicy Trusted
3. Uninstall existing versions of the Azure Stack PowerShell modules
Before installing the required version, make sure that you uninstall any previously installed Azure Stack AzureRM PowerShell modules. You can uninstall them by using one of the following two methods:
To uninstall the existing AzureRM PowerShell modules, close all the active PowerShell sessions, and run the following cmdlets:
PowerShell
Uninstall-Module AzureRM.AzureStackAdmin -Force
Uninstall-Module AzureRM.AzureStackStorage -Force
Uninstall-Module -Name AzureStack -Force
Delete all the folders that start with Azure from the C:\Program Files\WindowsPowerShell\Modules and C:\Users\AzureStackAdmin\Documents\WindowsPowerShell\Modules folders. Deleting these folders removes any existing PowerShell modules.
4. Connected: Install PowerShell for Azure Stack with Internet connectivity
Azure Stack requires the 2017-03-09-profile API version profile, which is available by installing the AzureRM.Bootstrapper module. In addition to the AzureRM modules, you should also install the Azure Stack-specific PowerShell modules.
Run the following PowerShell script to install these modules on your development workstation:
Version 1.4.0 (Azure Stack 1804 or greater)
PowerShell
# Install the AzureRM.Bootstrapper module. Select Yes when prompted to install NuGet
Install-Module -Name AzureRm.BootStrapper
# Install and import the API Version Profile required by Azure Stack into the current PowerShell session.
Use-AzureRmProfile -Profile 2017-03-09-profile -Force
# Install Module Version 1.4.0 if Azure Stack is running 1804 at a minimum
Install-Module -Name AzureStack -RequiredVersion 1.4.0
Version 1.2.11 (before 1804)
PowerShell
# Install the AzureRM.Bootstrapper module. Select Yes when prompted to install NuGet
Install-Module -Name AzureRm.BootStrapper
# Install and import the API Version Profile required by Azure Stack into the current PowerShell session.
Use-AzureRmProfile -Profile 2017-03-09-profile -Force
# Install Module Version 1.2.11 if Azure Stack is running a lower version than 1804
Install-Module -Name AzureStack -RequiredVersion 1.2.11
Confirm the installation by running the following command:
PowerShell
Get-Module -ListAvailable | where-Object {$_.Name -like “Azs*”}
If the installation is successful, the AzureRM and AzureStack modules are displayed in the output.
All seems simple, right?
PowerShell script demonstration
The following video demonstrates the Set-AzureStackPS script, which is available to download via the following URL.
Download
PowerShell for Azure Stack (34319 downloads)
Change Log
Version 1.1 – Features
- Improved error detection for failed PowerShell module installation
- Improved support for PSGallery detection
- Improve code structure
Reporting Issues
If you identity any issues within running the script please email theauthor@blogabout.cloud
Regards
The Author – Blogabout.Cloud