If you need to add existing VMs to Azure Stack. The process of adding new base images is described as follows and is quite similar to that of adding a new base OS:
- Log on to a computer with Azure PowerShell and Azure Stack PowerShell tools installed. In addition, we need the PowerShell tools for Azure Stack too.
- Import the Azure Stack Connect and ComputeAdmin PowerShell module to your administrative PowerShell ISE, as follows:
Import-Module .ConnectAzureStack.Connect.psm1 Import-Module .ComputeAdminAzureStack.ComputeAdmin.psm1
- Create the Azure Stack cloud administrator's AzureRM environment:
Add-AzureRMEnvironment ` -Name "AzureStackAdmin" ` -ArmEndpoint https://adminmanagement.local.azurestack.external
- Get the GUID from your Azure Stack tenant:
- In connected scenarios, this is the code:
- In disconnected scenarios, this is the code:
$TenantID = Get-AzsDirectoryTenantId ` -ADFS -EnvironmentName AzureStackAdmin
- Log in to your Azure Stack environment using the follow PowerShell command:
Login-AzureRmAccount ` -EnvironmentName "AzureStackAdmin" ` -TenantId $TenantID
- Add the existing image to the environment using the following PowerShell:
Add-AzsVMImage ` -publisher "Canonical" ` -offer "UbuntuServer" ` -sku "14.04.3-LTS" ` -version "1.0.0" ` -osType Linux ` -osDiskLocalPath
'C:UsersAzureStackAdminDesktopUbuntuServer.vhd'
The PowerShell command does the following steps:
- Authenticates to the Azure Stack environment.
- Uploads the local VHD to a newly created temporary storage account.
- Adds the VM image to the VM image repository.
- Creates a Marketplace item.
Parameter |
Description |
publisher |
The publisher name segment of the VM image that user's use when deploying the image. An example is Microsoft. Do not include a space or other special characters in this field. |
offer |
The offer name segment of the VM image that user's use when deploying the VM image. An example is WindowsServer. Do not include a space or other special characters in this field. |
sku |
The sku name segment of the VM image that user's use when deploying the VM image. An example is Datacenter2016. Do not include a space or other special characters in this field. |
version |
The version of the VM image that user's use when deploying the VM image. This version is in the format #.#.#. An example is 1.0.0. Do not include a space or other special characters in this field. |
osType |
The osType of the image must be either Windows or Linux. |
osDiskLocalPath |
The local path to the OS disk VHD that you are uploading as a VM image to Azure Stack. |
dataDiskLocalPaths |
An optional array of the local paths for data disks that can be uploaded as part of the VM image. |
CreateGalleryItem |
A Boolean flag that determines whether to create an item in Marketplace. By default, it is set to true. |
title |
The title name of Marketplace item. By default, it is set to the publisher-offer-sku of the VM image. |
description |
The description of the Marketplace item. |
location |
The location to which the VM image should be published. By default, this value is set to local. |
osDiskBlobURI |
Optionally, this script also accepts a Blob storage URI for osDisk. |
dataDiskBlobURIs |
Optionally, this script also accepts an array of Blob storage URIs in order to add data disks to the image. |
To remove an existing VM from the Marketplace, the PowerShell will change to the following:
Remove-AzsVMImage ` -publisher "Canonical" ` -offer "UbuntuServer" ` -sku "14.04.3-LTS" ` -version "1.0.0"