PowerShell: Build Windows 10 Server Technical Preview VM in Azure

You’ve probably heard about Windows 10 and the Windows Server Technical Preview, right? You can download the Windows 10 Client operating system from https://insider.windows.com, and you can download the Windows Server Technical Preview from your MSDN account, if you have one. A lot of people have stated that the download of the ISO images is taking hours on their slower Internet connections, so what if I told you that you could get up and running with Windows 10 Server Technical Preview, in just a matter of minutes? Does that sound like a good thing to you?

The Microsoft Azure team has enabled you to deploy infrastructure virtual machines (VMs) based on a Windows Server Technical Preview image. You can use PowerShell to deploy Azure virtual machines, and today we’re going to specifically take a look at how you can build a Windows Server Technical Preview VM in Azure, by using PowerShell! If you noticed my earlier embedded tweet, you’ll see that the Get-AzureVMImage command is used to discover which image in the Azure image gallery contains the Windows Server Technical Preview.

If you would rather deploy Azure virtual machines using the Azure Management Portal, check out the step-by-step directions over at Keith Mayer’s blog. Keith is a Development Platform Evangelist (DPE) with Microsoft for the Heartland region.


If you don’t already have a Microsoft Azure subscription, you’re going to need to sign up for it first. You can sign up for a free trial of Microsoft Azure, or you can simply sign up for a pay-as-you-go subscription by using a credit card. You’ll only be charged for the services you use, so if you are only running a virtual machine for a few hours, you will probably spend less than a dollar or two (US dollars).

In addition to the Microsoft Azure subscription, you’re going to need to install PowerShell version 4.0 (part of the Windows Management Framework Core 4.0 package) and then install the latest version of the Microsoft Azure PowerShell module. You can install Microsoft Azure PowerShell from the GitHub open-source project page. Click on the Releases link to find the latest stand-alone installer.

Provisioning a Windows Server Technical Preview Virtual Machine

Once you’ve installed Microsoft Azure PowerShell, fire up the PowerShell Integrated Scripting Editor (ISE). Copy and paste the template script below into the PowerShell ISE, and fill out the necessary details, as mentioned in comments below. There are also comments to help you inside of the script. You will need to edit the following details:

Azure Account Details

  • The username that you use to access your Microsoft Azure subscription, in the $AzureUsername variable
  • Your Azure subscription name in the $SubscriptionName variable

Azure Resource Properties

  • The storage account name to be globally unique. Use the Test-AzureName -Storage <NameHere> command to test validity of a storage account name.
  • The cloud service name for the virtual machine, under the $VMProps variable
  • The size of your Azure virtual machine, again under the $VMProps variable

Keep in mind that you can use the Test-AzureName command to check if a certain storage account name, or cloud service name, is valid and has not already been reserved by another Azure customer. For example, to check the validity of the storage account name, use: Test-AzureName -Storage ws2014lab. If you receive a return value of $false, then you can go ahead and use the globally unique resource name.

# Get your Azure credential and store it in a variable
$AzureUsername = 'user@domain.com';
$Credential = Get-Credential -UserName $AzureUsername -Message 'Please enter your Azure password.';

# Login to Microsoft Azure, and download subscription details
Add-AzureAccount -Credential $Credential;

# Select the correct Azure subscription
# NOTE: Use Get-AzureSubscription to find your subscription name
# NOTE: Azure Subscription names are case sensitive!!!
$SubscriptionName = 'Visual Studio Ultimate with MSDN';
Select-AzureSubscription -SubscriptionName $SubscriptionName;

# Create an Azure storage account to hold the VM
# NOTE: Use the Get-AzureLocation command to find Azure regions for the "Location" property
# NOTE: Use the Test-AzureName -Storage command to validate your storage account name
$StorageAccount = @{
    StorageAccountName = 'winservtechpreview'; # IMPORTANT: Set this to something that is globally unique.
    Location = 'North Central US';
    Description = 'This storage account contains the Windows Server Technical Preview VM.';
New-AzureStorageAccount @StorageAccount;
# Set your current storage account, where the VM will be created
Set-AzureSubscription -SubscriptionName $SubscriptionName -CurrentStorageAccountName $StorageAccount.StorageAccountName;

# Find the Windows Server Technical Preview image
(Get-AzureVMImage).Where({ $PSItem.ImageName -match 'Preview'; });

# Define the Windows Server Technical Preview image name
$ImageName = 'a699494373c04fc0bc8f2bb1389d6106__Windows-Server-Technical-Preview-201410.01-en.us-127GB.vhd';

# Build a HashTable of VM properties
# NOTE: Use the Test-AzureName -Service command to ensure that you are using a globally unique cloud service name
$VMProps = @{
    Windows = $true;                     # This just tells Azure we're provisioning a Windows VM
    ImageName = $ImageName;              # This is the Azure image name we defined up a few lines
    AdminUsername = 'Trevor';            # IMPORTANT: Specify a custom username for your administrative account
    Password = 'P@ssw0rd!';              # IMPORTANT: Set a custom password for your administrative account
    InstanceSize = 'Medium';             # IMPORTANT: Use Get-AzureRoleSize to determine which VM size to use
    Location = $StorageAccount.Location; # IMPORTANT: This must be the same region as your storage account
    ServiceName = 'wstechpreview';       # IMPORTANT: Set this to something globally unique.

# Create the Azure virtual machine, using the above properties (this is called splatting)
New-AzureQuickVM @VMProps;
New-AzureQuickVM Results

New-AzureQuickVM Results

Once you’ve finished editing the input variables for the script, go ahead and hit F5 to execute it. You will be prompted for your password to access your Microsoft Azure subscription, and the remainder of the script will execute. The last thing you should see in the console pane of the PowerShell ISE is a couple of operations from the New-AzureQuickVM command. If they are successful, then congratulations, you’ve successfully deployed a Windows Server Technical Preview virtual machine!

Accessing the Azure Virtual Machine

Remote Desktop Connection to the Windows Server Technical Preview VM

Remote Desktop Connection to the Windows Server Technical Preview VM

In order to access your new virtual machine using Remote Desktop Protocol (RDP), you can use the Get-AzureRemoteDesktopFile command. You’ll need to specify the -ServiceName (public cloud service name), -Name (virtual machine name inside the cloud service), and then finally specify the -Launch parameter to kick off the RDP session. You’ll be prompted for the credentials that you used in the $VMProps variable, which is your administrative account to access the VM. From this point, you can manage the VM just like any other! Go play around with Windows Server Technical Preview, and get your feet wet!

Here is the script that will initiate your remote desktop connection:

# The cloud service and VM name are both the same, since we used New-AzureQuickVM
Get-AzureRemoteDesktopFile -ServiceName $VMProps.ServiceName -Name $VMProps.ServiceName

PowerShell Remoting

If you want to remotely invoke PowerShell commands on the virtual machine, using PowerShell Remoting, use the following code as an example:

# Specify the PSSession options to skip certificate verification for self-signed certificates
$SessionOption = New-PSSessionOption -SkipCACheck -SkipCNCheck -SkipRevocationCheck;
# Get the URI to connect to the Azure virtual machine's WinRM service
$WinRMUri = Get-AzureWinRMUri -ServiceName $VMProps.ServiceName -Name $VMProps.ServiceName;
# Specify a PowerShell ScriptBlock to invoke on the remote system
$ScriptBlock = { (Get-CimInstance -ClassName Win32_OperatingSystem).Caption; };
# Get the administrative credential to authenticate to the virtual machine
$VMCredential = New-Object -TypeName pscredential `
    -ArgumentList $VMProps.AdminUsername, (ConvertTo-SecureString -AsPlainText -Force -String $VMProps.Password);

# Invoke the PowerShell command remotely
Invoke-Command -ConnectionUri $WinRMUri -SessionOption $SessionOption -ScriptBlock $ScriptBlock -Credential $VMCredential;


Once you follow the directions above, you will have provisioned a Microsoft Azure virtual machine running the Windows Server Technical Preview that was released on October 1st, 2014! Congratulations!