Nano Server in the Azure Gallery and VM Agent Support
As part of Windows Server 2016 General Availability, there are new Nano Server images in the Azure Gallery. In addition to the new image, there is also a helper script attached to this blog post that can be used to customize the image when deploying in Azure.
Nano Server now supports running a limited VM Agent when deploying in Azure, as well as the running of Extensions. Due to the small nature of Nano Server, most of the Windows extensions do not run on Nano Server and are not required. For Nano Server, we provide two special-case extensions:
- VMAccess: Used to change the Administrator password through the Azure interface
- CustomScript: Used for running arbitrary customization scripts
We are investigating adding additional extensions for Nano Server, so please use the comments section or the Nano Server UserVoice site at https://windowsserver.uservoice.com/forums/295068-nano-server to provide feedback on additional extensions you'd like to see.
The following examples show how to configure the CustomScript extension, depending on which portal you are using. Note that this blog post builds on our previous post describing how to create Nano Server VMs in Azure IaaS at https://blogs.technet.microsoft.com/nanoserver/2016/05/27/nano-server-tp5-iaas-image-in-azure-updated/.
Azure Service Manager
If the container already exists, you can skip its creation. The script file only needs to be uploaded once to Azure Storage.
New-AzureStorageContainer -Name "my-script-container" Set-AzureStorageBlobContent -File .\RunMe.ps1 -Container "my-script-container" $vm = Get-AzureVM -Name "my-vm" -ServiceName "my-service-name" $vm = Set-AzureVMCustomScriptExtension -VM $vm -ContainerName "my-script-container" -FileName "RunMe.ps1" -Run "RunMe.ps1" -Argument "MyArg1 MyArg2" $vm | Update-AzureVM
Azure Resource Manager
The module NanoServerAzureHelper.psm1 in the attached zip file provides a helper function: Set-HelperAzureRmCustomScript. This helper function makes the configuration easier, similar to Set-AzureVMCustomScriptExtension, and also provides automatic creation of storage accounts and containers and uploading of the scripts. Here are some examples of its use.
- To run a plain Windows command, without any scripts to download into the extension:
Set-HelperAzureRmCustomScript -ResourceGroupName "testrg001" -VMName "test-vm001" -Location "West US" -NoDownload -FullCommand "echo with No Download" -Verbose
- Set-HelperAzureRmCustomScript can create the storage account and container, if they didn't already exist. To upload the PowerShell script "RunMe.ps1" and an input data file from C:\MyScripts and run the script:
Set-HelperAzureRmCustomScript -ResourceGroupName "testrg001" -VMName "test-vm001" -Location "West US" -Account "my-storage" -NewAccount -Container "my-script-container" -NewContainer -Script "RunMe.ps1", "input.txt" -UploadPath "C:\MyScripts" -Arguments "With new accounts < input.txt" -Verbose
- To run a PowerShell script downloaded from a public resource:
Set-HelperAzureRmCustomScript -ResourceGroupName "testrg001" -VMName "test-vm001" -Location "West US" -ScriptUri "https://raw.githubusercontent.com/My/Dir/master/MyScript.ps1" -Arguments "With URI" -Verbose
- To run a PowerShell script that has been already uploaded to Azure storage:
Set-HelperAzureRmCustomScript -ResourceGroupName "testrg001" -VMName "test-vm001" -Location "West US" -Account "my-storage" -Container "my-script-container" -Script "RunMe.ps1" -Arguments "Without upload" -Verbose
Nano Server Azure Helper
Here is the Nano Server Azure Helper script module: