Nowadays Virtual Machines are used everywhere and considered essential for scalable resource management and of course faster to be provisioned compared to the physical ones.
In this article, we will look mainly MS Hyper-V services and servers can be managed via Hyper-V Manager or System Center VMM GUI and of course via PowerShell. There will be a reference to PowerCLI and VMWare ESXi.
So let’s start with the basics of some useful PowerShell cmdlets.
Get-VM
1 2 3 4 5 6 7 8 9 10 11 12 |
PS C:\WINDOWS\system32> get-vm Name State CPUUsage(%) MemoryAssigned(M) Uptime Status Version ---- ----- ----------- ----------------- ------ ------ ------- LAB-TEST-ALPINE Off 0 0 00:00:00 Operating normally 8.0 LAB-VM-CENTOS Off 0 0 00:00:00 Operating normally 8.0 LAB-TEST-KALI Off 0 0 00:00:00 Operating normally 5.0 LAB-VM-UBUNTU Off 0 0 00:00:00 Operating normally 8.0 LAB-VM-WIN10 Running 0 740 3.22:36:17.7000000 Operating normally 8.0 LAB-VM-WIN8 Off 0 0 00:00:00 Operating normally 8.0 LAB-VM-WS2012r2 Off 0 0 00:00:00 Operating normally 8.0 LAB-VM-WS2016-01 Off 0 0 00:00:00 Operating normally 8.0 LAB-VM-WS2016-02 Running 0 2606 11.03:43:36.4460000 Operating normally 8.0 |
Get a list of all your VMs used for testing purpose in your LAB-test*.
1 2 3 4 5 6 |
PS C:\WINDOWS\system32> get-vm LAB-test* Name State CPUUsage(%) MemoryAssigned(M) Uptime Status Version ---- ----- ----------- ----------------- ------ ------ ------- LAB-TEST-KALI Off 0 0 00:00:00 Operating normally 5.0 LAB-TEST-ALPINE Off 0 0 00:00:00 Operating normally 8.0 |
Using Start-VM with the pipeline to start them in a one-liner script:
1 |
PS C:\WINDOWS\system32> get-vm lab-test* | Start-VM |
Perform or List ChecksPoints of the VMs with Checkpoint-VM and Get-VMCheckpoint cmdlets:
1 2 3 4 5 6 7 8 |
PS C:\WINDOWS\system32> get-vm lab-test* | Checkpoint-VM -SnapshotName CreatedWithPowershell PS C:\WINDOWS\system32> get-vm lab-test* | Get-VMCheckpoint VMName Name SnapshotType CreationTime ParentSnapshotName ------ ---- ------------ ------------ ------------------ LAB-TEST-KALI CreatedWithPowershell Standard 22/07/2017 7:01:33 AM LAB-TEST-ALPINE CreatedWithPowershell Standard 22/07/2017 7:01:35 AM |
Can you imagine how simple can be to start or stop even a large number of VMs with a single script?
Or perform checkpoints, Measure, Migrate VMs… and then running when it’s needed or schedule the task to fully automate the whole process?
Hyper-V module
https://technet.microsoft.com/en-us/itpro/powershell/windows/hyper-v/hyper-v
VM WARE
Speaking of Virtualization this post can’t be complete without VM Ware, that is considered the top player in this field. PowerCLI is a command-line and scripting tool based on PowerShell and used for automating management and configuration of VMware vSphere.
Get-VM
https://www.vmware.com/support/developer/windowstoolkit/wintk40u1/html/Get-VM.html