Add a custom image to Azure Stack

2 minute read

In this blog post I will explain how you can add multiple custom images to Azure Stack.

At cubesys we have a brand new Azure Stack environment that we use as a demo and test environment for our consultants. Each consultant has his own subscription with pre-defined quotas that they can use to build, test and destroy whenever and whatever they want to test. One of our senior consultants asked me to add the following custom images as he wanted to test and validate a System Center upgrade scenario:

  • Windows 7 SP1 x64 Enterprise
  • Windows 8.1 x64 Enterprise
  • Windows 10 (Build 1511) x64 Enterprise
  • Windows Server 2008 R2 SP1 Datacenter
  • Windows Server 2012 Datacenter

So let’s make our tenant happy shall we?

Sysprep the virtual machines

Initially you will have to sysprep the virtual machines.

  1. Create a new virtual machine in Hyper-V
    1. make sure it’s generation 1
    2. and the hard drive needs to be VHD and not VHDX
  2. Install the operating system



  1. Once the operating system is installed you need to sysprep the machine using the following command
    1. For Windows 8 and after:
      1. open a Command Prompt window as an administrator, and then move to the %WINDIR%\system32\sysprep directory.
      2. Run the following command: [php]Sysprep /generalize /shutdown  /oobe /mode:vm[/php]
    2. Anything before Windows 8
      1. open a Command Prompt window as an administrator, and then move to the %WINDIR%\system32\sysprep directory
      2. Run the following command: [php] Sysprep /generalize /shutdown /oobe [/php]


Once complete the virtual machines will shutdown automatically. Copy the sysprepped virtual hard drives to another location. In my case E:\templates



Add the image to the Platform Image Repository

Once we have all our virtual machines sysprepped and have copied the virtual hard drives we can add them to Azure Stack. To add a new image to Azure stack it needs to be added to the Platform Image Repository or PIR. Microsoft has provided a PowerShell script (CopyImageToPlatformImageRepository.ps1) to do this.

You can find this PowerShell script on the MicrosoftAzureStackPOC.vhd virtual hard drive.

  • Right click on the vhd file and mount the VHD
  • Get the Drive letter of the DATAIMAGE drive



  • Use PowerShell and Navigate to D:\CRP\VM\Microsoft.AzureStack.Compute.Installer\content\Scripts where you will find the CopyImageToPlatformImageRepository.ps1 PowerShell script


The script requires the following parameters:

  1. For PlatformImageRepositoryPath, type <a href="file://\\SOFS\Share\CRP\PlatformImages\">\\SOFS\Share\CRP\PlatformImages\</a>
  2. For ImagePath, type the path to the PIR image. In my case ‘C:\templates\Sysprep2008R2.vhd’
  3. For Publisher, type a publisher name, like Microsoft.
  4. For Offer, type any value, like WindowsServer.
  5. For Sku, type a SKU for the image, like 2008-R2.
  6. For Version, type a version in #.#.# format, like 1.0.0.
  7. For OsType, type Windows or Linux.

Make sure the -Offer and/or -SKU does not contain a space or the manifest will be invalid and a gallery item will not be created.

We can now use the parameters above to launch the script:

[php].\CopyImageToPlatformImageRepository.ps1 -PlatformImageRespositoryPath \SOFS\Share\CRP\PlatformImages\ -ImagePath ‘C:\templates\Sysprep2008R2.vhd’ -Publisher “Microsoft” -Offer “WindowsServer” -Sku “2008-R2” -Version 1.0.0 -OsType Windows –Verbose[/php]

  • Once complete navigate to [\SOFS\Share\CRP\PlatformImages](file://sofs/Share/CRP/PlatformImages/) and you will see your image with a manifest.json file.



After the command completes, restart your browser to see the new item in the Marketplace. The image can now be referenced in your virtual machine deployment templates. In some instances it may take up to 5 minutes for this new image to appear in the Marketplace.





Leave a comment