
May 22, 2015
Whilst there have some great new features, updates and bug fixes in PowerShell 4.0, I think the new Hyper-V cmdlets added in PS 4.0 have been largely overlooked. However, I think they are worthy of extra attention, and give us poor Hyper-V administrators some very useful features and automation capabilities in managing our Virtual Machines.
There are 13 brand new cmdlets directly related to Hyper-V in PowerShell 4.0 and they are listed and described below. I have also hyperlinked each command to their full descriptions in Microsoft’s TechNet website, so you can reference their complete syntax and detailed description.
Copy-VMFile As the name implies, the Copy-VMFile allows you to copy files into your Virtual Machines. It does require Hyper-V 3.0 (on Server 2012 R2 and Windows 8.1), the Integrated Services Version must be at least 6.3.9600.16384 (i.e. Server 2012 R2 or Windows 8.1) and Guest Services must be enabled. The CodePlex website guys have even written a neat little GUI as a front end for the Copy-VMFile command – it can be found here. Get-VMFirmware / Set-VMFirmware Server 2012 R2 and Windows 8.1 brought in Generation 2 Virtual Machines, and with the new Get/Set-VMFirmware commands we can now retrieve or set the firmware boot order and other firmware configuration settings for our Gen 2 VM’s (Get/Set-VMBIOS is used for the Gen 1 VM’s).
Debug-VM
This new PowerShell v4.0 command enables you to get a kernel dump of a VM in Server 2012 R2. It does this by injecting a non-maskable interrupt into the VM. The basic syntax is:
Debug-VM –Name “VM_Name” –InjectNonMaskableInterrupt -ForceAdd-VMNetworkAdapterExtendedAcl
Get-VMNetworkAdapterExtendedAcl
Remove-VMNetworkAdapterExtendedAcl
These three commands reference the Extended Port Access Control Lists (ACLs) that is new in Windows Server 2012 R2. The Extended Port ACLs let you create firewall rules that apply to the individual virtual NICs within a VM, and you can only create and manage these rules through PowerShell. They allow you to filter inbound and outbound traffic or both, The main update to ACLs here is that you can not only create ACLs based upon MAC and IP addresses as in Windows Server 2012, but R2 now adds the ability to use socket port numbers as well. These extended ACLs give you many more options in your firewall rules and are especially useful in multi-tenant environments.

Get-VmNetworkAdapterIsolation
Set-VmNetworkAdapterIsolation
These two commands can retrieve or set network isolation settings on your VM’s Network adapter. You can isolate the adapter by either Virtual Local Area Network (VLAN), Hyper-V Network Virtualisation or third part network virtualisation settings. Again these commands are geared towards multi-tenant settings.

Add-VmNetworkAdapterRoutingDomainMapping
Get-VMNetworkAdapterRoutingDomainMapping
Remove-VMNetworkAdapterRoutingDomainMapping
Set-VmNetworkAdapterRoutingDomainMapping
Another set of commands geared towards multi-tenanted environments. These commands allows you to add, view, configure and remove specified routing domains and virtual subnets for tenants to the virtual network adapters associated with your multi-tenant virtual machines.
So there you have them, a quick intro to a number of new PowerShell/Hyper-V commands with some great new configurations geared for multi-tenant environments. But these can actually be of use to us even if we don’t have a multi-tenant environment – this new network virtualisation architecture Microsoft has given us in Windows Server 2012 R2 helps us to live-migrate VM’s to Hyper-V hosts that reside in remote subnets, such as a remote datacenter, without having to make changes to the VM’s IP Address, and allows us to set firewall rules that apply to individual NICs within a VM etc. etc.
Of course, my favourites are the Copy-VMFile command that lets me copy files into my new VM’s, and the Set-VMFirmware command that allows me to change the boot order of my VM. So what are your favourites, and what scenarios can you see them used in?
How do your Excel skills stack up?
Test NowNext up:
- Understanding the difference between Office 2013 and Office 365
- Virtualising SQL Server using Hyper-V 3.0 and SCVMM
- The science of presenting (Part 3)
- PivotTable timelines in Excel 2013
- Recursive functions in VBA
- Troubleshooting an upgrade to Exchange Server 2013
- Troubleshooting Office 365: Real solutions
- Creating Quick Parts in Microsoft Word
- Who does what in managing change?
- Taking a closer look at Universal Apps
Previously
- Remove those rogue records in Excel
- The art of thinking clearly
- Managing application settings in Windows Store Apps
- Find a filter result without filtering in Excel
- What is new in Office 365
- Quick ways to automate in Photoshop – Part 2: Modifying an Action
- How to avoid reinventing the wheel
- How to create an e-mail template in Outlook
- How to scrape a website
- Round, RoundUp and RoundDown in Excel