Team blog of MCS @ Middle East and Africa

This blog is created by Microsoft MEA HQ near shoring team, and it aims to share knowledge with the IT community.With its infrastructure and development sides,It brings to you the proven best practices and real world experiences from Subject Matter Experts
Follow Us On Twitter! Subscribe To Our Blog! Contact Us

Windows Server 8 – Manage Hyper-V 3.0 with PowerShell

Windows Server 8 – Manage Hyper-V 3.0 with PowerShell

  • Comments 1
  • Likes

One of the major feature of Windows Server 8 is Hyper-V 3.0 This new version of Microsoft virtualization platform brings great improvements and features.

In this blog post we’ll cover a couple of Windows Server 8 Hyper-V PowerShell command lets. Using PowerShell cmdlet will reduce most of day-to-day administrative tasks.

Open Windows PowerShell ISE and begin with first command;

get-vm

Get-VM cmdlet outputs all virtual machines that hosted on local Hyper-V server. As you seen above, it warns us about missing columns. To get more user friendly output, use Format List

get-vm_fl

Get-VM will give you a general idea about virtual machine’s state. That means you can use filters to get specific virtual machine states.

get-vm_2

I used Get-VM cmdlet again but with pipeline and $_. special character. It filters the output to show me only virtual machines that status fields equal “Operating Normally”

Another helpful command is Checkpoint-VM. This cmdlet starts snapshot process for specified virtual machine.

Try get-help to learn which syntax and parameters available for CheckPoint-VM

checkpoint_gethelp

I can use –name parameter to specify virtual machine.

Now firstly I used Get-VM to specify virtual machine and then pipe that information to Checkpoint-VM cmdlet.

checkpoint

As you notice, snapshot process began and finished.

checkpoint_status

Well, what about reverting Virtual Machines to the previous checkpoints? You can check all snapshots for a specific virtual machine with Get-VMSnapshot cmdlet. Required parameter is –VMName.

get-vmsnapshot

Now you have all checkpoint information for a specific VM. That means you can pipe this data to the Restore-VMSnapshot cmdlet.

In below example I used another method to pipe required data. As you see I use Get-VMSnapshot cmdlet’s name property as a Restore-VMSnapshot Name parameter.

But it gives me a confirm popup.

restore-vmsnapshot

If you want to automate administrative tasks through PowerShell, you need to suppress some of confirm dialogs. It is possible with –confirm parameter.

restore-vmsnapshot2

Restoring snapshot..

restore-vmsnapshot3

Let’s look at other cmdlets. Networking is a major component of Hyper-V. Get-VMNetworkAdaptor gives you network interface details of virtual machines.

get-vmnetworkadapter

Also you can use Get-VMSwitch to get Hyper-V network switch details.

get-vmswitch

Let’s try to add another switch to Hyper-V. You need to specify physical network adapter name with –NetAdapterName parameter.

new-vmswitch_hata

As you see above, it couldn't find any related network adapter on local host. To learn your physical network adapter names just run Get-Netadapter.

get-networkadaptor

get-networkadaptor2

I assigned net adapter name which have a “UP” status value to a variable called $AdapterName.

Now execute New-VmSwitch cmdlet again. But I gives me another error:

new-vmswitch_hata2

It says my physical network adapter is already in use. Let me check.

get-vmswitch2

Yeap. There is already a Hyper-V switch that uses my current physical adaptor and has a “External” switch type. I can convert that Hyper-V switch type from External to Private. That will let free my physical interface.(Wi-Fi)

set-vmswitch

Now creating again.

new-vmswitch_ekledi

You can check from Virtual Switch Manager. As you see a new switch added and bind to physical network card.

hyper-v swicth ekranı

PowerShell can also be used to modify other virtual machine hardware components. Add-VMHardDisk attaches virtual hard disk files (VHD/VHDX) to a VM as additional disks.

add-vmharddisk_hata

But of course firstly you have to create vhdx file separately. Use New-VHD cmdlet.

new-vmdisk

Now you can assign previously created virtual hard disk to a specific VM.

add-vmharddisk_tamam

Here is our newly added disk on Hyper-V manager.

hyper-v disk ekranı

There are bunch of commands that helps you to manage Hyper-V 3.0 on Windows Server 8. In my next blog I’ll cover them.

Thanks.

Anıl Erduran.

Comments
  • Really love how Microsoft is taking PoweShell deep into everything!

Your comment has been posted.   Close
Thank you, your comment requires moderation so it may take a while to appear.   Close
Leave a Comment