If you for example don’t have System Center Virtual Machine Manager or another tool to create Virtual Machine Templates and automate the deployment, you can also do this using Sysprep, PowerShell and an unattend.xml file to automate or simplify the Virtual Machine creation process. In other blog posts I already wrote how you can sysprep Virtual Machines or how you can create Hyper-V Virtual Machines using PowerShell. In this post I will show you how you can add an unattend.xml file to your VHD or VHDX so your virtual machine gets some default settings like regional information.

Here we have a basic unattend.xml file. If you want to enhance it, or create your own, you can also use the Windows ADK.

To use this unattend.xml you first have to sysprep a virtual machine and create a sysprep VHD file. After that you can mount the VHDX file and insert the unattend.xml file to the VHD. Copy the unattend.xml file to the following location: D:\Windows\Panther (in my case the VHD was mounted as D drive).

For using the same system image for different virtual machines or physical computer, Microsoft created a tool called sysprep.exe. This blog post covers Most people should be already familiar with that tool. If not here is the description:

Sysprep prepares a Windows installation (Windows client and Windows Server) for imaging, allowing you to capture a customized installation. Sysprep removes PC-specific information from a Windows installation, “generalizing” the installation so it can be reused on different PCs. With Sysprep you can configre the PC to boot to audit mode, where you can make additional changes or updates to your image. Or, you can configure Windows to boot to the Out-of-Box Experience (OOBE).

This is great so you can sysprep a virtual machine copy the VHD or VHDX file and use it for the first boot of different VMs. In Windows Server 2012 and Windows 8, Microsoft added an addition to sysprep called the mode switch “/mode:vm”. The mode:vm switch allows you to identify the Windows as a Virtual Machine and sysprep.exe will generalize a Virtual Hard Disk (VHD or VHDX) so that you can deploy the VHD as a VHD on the same Virtual Machine (VM) or hypervisor. You must deploy the VHD on a Virtual Machine (VM) or hypervisor with the same hardware profile. For example, if you created VHD in Microsoft Hyper-V, you can only deploy your VHD to Microsoft Hyper-V VMs with a matching hardware profile, and you can only run VM mode from inside a VM.

This will boost the performance and time for the virtual machine for the first startup and installation. This also work of course with virtual machines running on other hypervisors such as VMware or Xen.

Run the following command inside the Virtual Machine (You find sysprep.exe in the C:\Windows\System32\Sysprep folder):

Around 4 years ago I wrote a blog post about how to Replace netsh with Windows PowerShell which includes basic powershell networking cmdlets. After working with Microsoft Azure, Nano Server and Containers, PowerShell together with networking becomes more and more important. I created this little cheat sheet so it becomes easy for people to get started.

This is one of the first post of a short blog series with some simple PowerShell scripts and oneliners for Hyper-V. One this is how you can connect a Virtual Network Adapter of a Hyper-V Virtual Machine to another Virtual Switch.

This is very simple, with this command you can see all the Network Adapters of the Virtual Machine and to which Switch they are connected:

When you were create a USB media for PCs, notebooks and servers which were using BIOS you could use several tools to do this. Now most of the tools do not really create a USB media drive which can be used to boot and install Windows or Windows Server on a UEFI based system such a new servers and for example the Surface Pro line. But it is very simple to do this now, just follow this steps:

The USB drive has to be formatted in FAT32

The USB needs to be GPT and not MBR

Copy all files from the ISO to the USB drive

PowerShell to create a Windows Server USB drive

This is it, and here is how you do it:

First plugin your USB drive to your computer. The USB drive should be bigger than 4GB.

Open a CMD prompt or PowerShell using the Run as Administrator option and open diskpart. Now you can do list all this by using

1

list disk

Select the USB disk, in my case this was disk 1

1

select disk1

Clean the disk. Be careful this will remove all files and partitions on the USB media.

1

clean

Now convert it to GPT

1

convert gpt

Create a new primary partition. But make sure the partition is not greater than 16GB otherwise it can be formatted with FAT32.

1

2

3

4

5

create partition primary

# If your USB drive is bigger than 16GB use the following command

create partition primary size=16000

Format the partition with FAT32

1

format fs=FAT32 quick

Assign a drive letter to the volume

1

assign letter=k

now you can exit the diskpart and copy all files from the Windows or Windows Server to the USB drive and boot it. This works with Windows 8, Windows 8.1, Windows 10, Windows Server 2012, Windows Server 2012 R2 and Windows Server 2016 or even Hyper-V Server in the same editions.

Veeam does some great products for your virtualization and datacenter environment such as their Veeam Backup & Replication suite, Veeam Endpoint Backup FREE and Management Packs for System Center Operations Manager. Now a couple of weeks ago Veeam released a cool free tool call Veeam FastSCP fro Microsoft Azure. With Veeam FastSCP (Secure Copy Protocol) for Microsoft Azure, IT Pros and Azure Developers can simply and reliably copy local files to Azure VMs, and copy files in Azure VMs to on-premises.

The utility makes your life way easier when dealing with Virtual Machines running on Microsoft Azure IaaS.

Secure file copy with no independent encryption or VPN needed

Manual file copy to/from Azure VMs without the need to keep the UI open until the file copy completes

To set it up the tool connects to the PowerShell endpoint for your IaaS VM. Just add the Virtual Machine and you are ready to go! With that you can do some great things, like simply copy a file to an Azure IaaS VM or even doing scheduled backups of files from inside Azure VMs like Didier Van Hoye did.

Well I was working in on a Private Cloud Deployment where we had some temporary storage for our Hyper-V Virtual Machines and after we got the right storage ready, which was btw a Windows Server Scale-Out File Server Cluster running with Storage Spaces and DataON JBOD chassis, we had to migrate the storage of all virtual machines running on our Hyper-V hosts. Since Windows Server 2012 offers Live Storage Migration which allows us to move the Virtual Machine to a different storage location without downtime we would use that. But if you have to move around 20 virtual machines you think twice if you want to move that via the Hyper-V Manager GUI or Windows PowerShell.

Here is a pretty simple PowerShell foreach loop which moves the storage of all virtual machines running on the Hyper-V host.

Follow Me

About

My name is Thomas Maurer. I am a Senior Cloud Advocate at Microsoft. I am part of the Azure engineering team and engage with the community and customers around the world. I am located in Switzerland. I am focusing on Microsoft technologies, especially cloud and datacenter solutions based on Microsoft Azure, Azure Stack and Windows Server. Opinions are my own.