Basic commands for virtual machine management
Get-VM
This command gives users a list of all virtual machines across multiple host servers. Users can filter the VM list for specific host servers. Additionally, Get-VM command allows users to export the VM list into CSV format. Here are some examples:
PS C:\> Get-VM
PS C:\> Get-VM ComputerName Server1
PS C:\> Get-VM ComputerName Server1 | EXPORT-CSV C:\Powershell\VMlist.csv
Get-VM Summary
This command gives users detailed information about any virtual machine. This command results in information such as CPU counts, number of snapshots, guest OS, uptime, hostname, IP address, FQDN, CPU load, memory usage, and more. Following is the syntax:
PS C:\> Get-VMSummary VM01
PS C:\> Get-VMSummary VM03 ComputerName Server1
New-VM
The New-VM command creates a new virtual machine. This command allows users to define additional parameters to set VM configuration such as VM generation, startup memory, boot device and VHD path (for both new and existing VHD files).
PS C:\> New-VM Name "VM04" MemoryStartupBytes 512MB
PS C:\> New-VM Name "VM05" MemoryStartupBytes 1GB VHDPath d:\vhd\BaseImage.vhdx
PS C:\> New-VM Name "new 2" MemoryStartupBytes 1GB NewVHDPath d:\vhd\base.vhdx
Start- and Stop-VM
The Start-VM command allows users to start a virtual machine. Users either can start a single VM or can define more parameters to run this command for starting multiple virtual machines.
PS C:\> Start-VM Name VM01
PS C:\> Start-VM VM0* -asjob
Similarly, the Stop-VM command allows users to stop single or multiple virtual machines simultaneously.
PS C:\> Stop-VM VM0*
PS C:\> Stop-VM VM01 turnoff
PS C:\> Stop-VM VM01 save force
Image: Microsoft TechNet