One of the major features of Windows Server 8 is Hyper-V 3.0 This new version of Microsoft virtualization platform brings great improvements and features.
In this article 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 the first command:
One of the major features of Windows Server 8 is Hyper-V 3.0 This new version of Microsoft virtualization platform brings great improvements and features. In this article we’ll cover a couple of Windows Server 8 Hyper-V PowerShell command lets. Using PowerShell cmdlet will reduce most ofunityserver-blogs-components-weblogfiles/00-00-00-79-57-metablogapi/4111.get_2D00_vm_5F00_777A1B96.png"> Get-VM cmdlet outputs all virtual machines that hosted on local Hyper-V server. As you see above, it warns us about missing columns. To get more user friendly output, use Format List
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. 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 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. As you notice, snapshot process began and finished. 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. 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. If you want to automate administrative tasks through PowerShell, you need to suppress some of confirm dialogs. It is possible with
–confirm parameter. Restoring snapshot.. Restoring snapshot.. Let’s look at other cmdlets. Networking is a major component of Hyper-V.
Get-VMNetworkAdaptor gives you network interface details of virtual machines.
Also you can use Get-VMSwitch to get Hyper-V network switch details. Let’s try to add another switch to Hyper-V. You need to specify physical network adapter name with
–NetAdapterName parameter. 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. 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: It says my physical network adapter is already in use. Let me check. 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) Now creating again. You can check from Virtual Switch Manager. As you see a new switch added and bind to physical network card. 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. But of course firstly you have to create vhdx file separately. Use New-VHD cmdlet. Now you can assign previously created virtual hard disk to a specific VM. Now you can assign previously created virtual hard disk to a specific VM. Here is our newly added disk on Hyper-V manager. 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 ErduranWindows Server 8 – Manage Hyper-V 3.0 with PowerShell
Also, the management of PVLAN and ACLs on Windows Server 8 Beta
only through Powershell.