VM Category | Vmware PowerCLI Reference

VM Category

Cmdlets are usually implemented around resource operations. The four basic operations are CREATE, READ, UPDATE and DELETE. This set of operations is known as CRUD. Most of the cmdlets support CRUD which are respectively cmdlets that start with the New/Get/Set/Remove cmdlet verbs but they also may have additional operations

Step 1: Retrieve a object by running a Get command

You can READ objects by using Get-VM cmdlet. See example below:

# Retrieves all virtual machines whose names starting with "MyVM".

Get-VM -Name MyVM*

Step 2 : Run commands from the CRUD group

You can CREATE objects by using New-VM cmdlet. See example below:

# Creates a virtual machine by specifying a target host, a target datastore, and a network to connect to, and configures the settings for the virtual machine.

$myTargetVMHost = Get-VMHost -Name MyVMHost1 New-VM -Name MyVM1 -ResourcePool $myTargetVMHost -Datastore MyDatastore1 -NumCPU 2 -MemoryGB 4 -DiskGB 40 -NetworkName "VM Network" -Floppy -CD -DiskStorageFormat Thin -GuestID winNetDatacenterGuest
You can UPDATE objects by using Copy-VMGuestFile cmdlet. See example below:

# Copies the text.txt file from the guest OS system to the local Temp directory.

Copy-VMGuestFile -Source c:\text.txt -Destination c:\temp\ -VM VM -GuestToLocal -GuestUser user -GuestPassword pass2
You can REMOVE objects by using Remove-VM cmdlet. See example below:

# Removes the 'myVM' virtual machine and deletes its files from the ESXi host.

Remove-VM -VM 'myVM' -DeletePermanently

Step 3: Explore More Related Commands:

Get-VMGuest This cmdlet retrieves the guest operating systems of the specified virtual machines.
Get-VMGuestDisk This cmdlet retrieves storage volumes as seen by the virtual machines' guest operating systems.
Get-VMQuestion This cmdlet retrieves the pending questions for the specified virtual machines.
Get-VMResourceConfiguration This cmdlet retrieves information about the resource allocation between the selected virtual machines.
Get-VMStartPolicy This cmdlet retrieves the start policy of the virtual machines on a vCenter Server system.
Invoke-VMScript This cmdlet runs a script in the guest OS of each of the specified virtual machines.
Move-VM This cmdlet moves virtual machines to another location.
Open-VMConsoleWindow This cmdlet opens a window to the virtual machine's console.
Restart-VM This cmdlet restarts the specified virtual machines.
Restart-VMGuest This cmdlet restarts the virtual machine guest operating systems.
Set-VM This cmdlet modifies the configuration of the virtual machine.
Set-VMQuestion This cmdlet answers the specified virtual machine question.
Set-VMResourceConfiguration This cmdlet configures resource allocation between the virtual machines.
Set-VMStartPolicy This cmdlet modifies the virtual machine start policy.
Start-VM This cmdlet powers on virtual machines.
Stop-VM This cmdlet powers off virtual machines.
Stop-VMGuest This cmdlet shuts down the specified virtual machine guest OS.
Suspend-VM This cmdlet suspends virtual machines.
Suspend-VMGuest This cmdlet suspends the specified guest operating systems.
Unlock-VM This cmdlet unlocks the specified virtual machine.