In this blog post I will explain how you can add multiple custom images to Azure Stack.
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 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
First of all you will have to sysprep the virtual machines.
- Create a new virtual machine in Hyper-V
- make sure it’s generation 1
- and the hard drive needs to be VHD and not VHDX
- Install the operating system
- Once the operating system is installed you need to sysprep the machine using the following command
- For Windows 8 and after:
- open a Command Prompt window as an administrator, and then move to the %WINDIR%\system32\sysprep directory.
- Run the following command:
Sysprep /generalize /shutdown /oobe /mode:vm
- Anything before Windows 8
- open a Command Prompt window as an administrator, and then move to the %WINDIR%\system32\sysprep directory
- Run the following command:
Sysprep /generalize /shutdown /oobe
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 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:
- For PlatformImageRepositoryPath, type
- For ImagePath, type the path to the PIR image. In my case ‘
- For Publisher, type a publisher name, like Microsoft.
- For Offer, type any value, like WindowsServer.
- For Sku, type a SKU for the image, like 2008-R2.
- For Version, type a version in #.#.# format, like 1.0.0.
- For OsType, type Windows or Linux.
We can now use the parameters above to launch the script:
.\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
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 cases it may take up to 5 minutes for this new image to appear in the Marketplace.