Set-VM Command | Vmware PowerCLI Reference

Set-VM

This cmdlet modifies the configuration of the virtual machine. If the OSCustomizationSpec parameter is used, the cmdlet customizes the virtual machine according to the specification. In addition, the cmdlet allows you to revert a virtual machine to a snapshot and convert a virtual machine to a template.

Syntax

Set-VM
-DisableEncryption
[-RunAsync ]
[-Server < VIServer[] > ]
[CommonParameters]

Parameters

Required Parameter Name Type Position Features Description
required
DisableEncryption SwitchParameter named
Indicates that you want to decrypt the specified virtual machine.
required
VM VirtualMachine[] named
  • pipeline
Specifies the virtual machine that you want to configure.
optional RunAsync SwitchParameter named
Indicates that the command returns immediately without waiting for the task to complete. In this mode, the output of the cmdlet is a Task object. For more information about the RunAsync parameter, run "help About_RunAsync" in the VMware PowerCLI console.
optional Server VIServer[] named
Specifies the vCenter Server systems on which you want to run the cmdlet. If no value is provided or $null value is passed to this parameter, the command runs on the default servers. For more information about default servers, see the description of the Connect-VIServer cmdlet.
Set-VM
[-AlternateGuestName < String > ]
[-BootDelayMillisecond < Int64 > ]
[-CoresPerSocket < Int32 > ]
[-CpuHotAddEnabled < Boolean > ]
[-CpuHotRemoveEnabled < Boolean > ]
[-DrsAutomationLevel < DrsAutomationLevel > ]
[-GuestId < String > ]
[-HAIsolationResponse < HAIsolationResponse > ]
[-HARestartPriority < HARestartPriority > ]
[-HardwareVersion < String > ]
[-MemoryGB < Decimal > ]
[-MemoryHotAddEnabled < Boolean > ]
[-MemoryMB < Int64 > ]
[-MigrationEncryption < VMMigrationEncryptionMode > ]
[-Name < String > ]
[-Notes < String > ]
[-NumCpu < Int32 > ]
[-OSCustomizationSpec < OSCustomizationSpec > ]
[-RunAsync ]
[-SEVEnabled < Boolean > ]
[-Server < VIServer[] > ]
[-VMSwapFilePolicy < VMSwapfilePolicy > ]
[-Version < VMVersion > ]
[CommonParameters]

Parameters

Required Parameter Name Type Position Features Description
required
VM VirtualMachine[] named
  • pipeline
Specifies the virtual machine that you want to configure.
optional AlternateGuestName String named
Specifies the full name of the guest OS for the virtual machine if the value of the GuestID parameter is set to otherGuest or otherGuest64.
optional BootDelayMillisecond Int64 named
Specifies the time interval in milliseconds between a virtual machine power on or restart and the beginning of the boot sequence.
optional CoresPerSocket Int32 named
Specifies the number of virtual CPU cores per socket.
optional CpuHotAddEnabled Boolean named
Specifies if virtual processors can be added to the virtual machine while it is running.
optional CpuHotRemoveEnabled Boolean named
Specifies if virtual processors can be removed from the virtual machine while it is running.
optional DrsAutomationLevel DrsAutomationLevel named
Specifies a Distributed Resource Scheduler (DRS) automation level. The valid values are FullyAutomated, Manual, PartiallyAutomated, AsSpecifiedByCluster, and Disabled. Passing values to this parameter through a pipeline is deprecated and will be deactivated in a future release. Specifying this parameter is only supported when the virtual machine is inside a cluster. Otherwise, an error appears.
optional GuestId String named
Specifies the guest operating system of the virtual machine. The valid values for specific ESX versions are listed in the description of the VirtualMachineGuestOsIdentifier enumeration type in the vSphere API Reference available at http://www.vmware.com/support/developer/vc-sdk/. Depending on the hardware configuration of the host, some of the guest operating systems might be inapplicable.
optional HAIsolationResponse HAIsolationResponse named
Indicates whether the virtual machine should be powered off if a host determines that it's isolated from the rest of the compute resource. The valid values are AsSpecifiedByCluster, PowerOff, and DoNothing. Passing values to this parameter through a pipeline is deprecated and will be deactivated in a future release. Specifying this parameter is only supported when the virtual machine is inside a cluster. Otherwise, an error appears.
optional HARestartPriority HARestartPriority named
Specifies the virtual machine High Availability (HA) restart priority. The valid values are Disabled, Lowest, Low, Medium, High, Highest and ClusterRestartPriority. VMware HA is a feature that detects failed virtual machines and automatically restarts them on alternative ESX hosts. Passing values to this parameter through a pipeline is deprecated and will be deactivated in a future release. Specifying this parameter is only supported when the virtual machine is inside a cluster. Otherwise, an error appears.
optional HardwareVersion String named
Specifies the version to which you want to upgrade the virtual machine. You cannot downgrade to an earlier version.
optional MemoryGB Decimal named
Specifies the memory size in gigabytes (GB).
optional MemoryHotAddEnabled Boolean named
Specifies if memory can be added to the virtual machine while it is running.
optional MemoryMB Int64 named
This parameter is obsolete. Use MemoryGB instead. Specifies the memory size in megabytes (MB).
optional MigrationEncryption VMMigrationEncryptionMode named
Specifies the encryption behavior when migrating the virtual machine. Valid options are: - Disabled: Do not use encrypted vSphere vMotion. - Opportunistic: Use encrypted vSphere vMotion if source and destination hosts support it. Only ESXi versions 6.5 and later use encrypted vSphere vMotion. - Required: Allow only encrypted vSphere vMotion. If the source or destination host does not support encrypted vSphere vMotion, migration with vSphere vMotion is not allowed.
optional Name String named
Specifies a new name for the virtual machine.
optional Notes String named
Provides a description for the virtual machine. The alias of this parameter is Description.
optional NumCpu Int32 named
Specifies the number of virtual CPUs.
optional OSCustomizationSpec OSCustomizationSpec named
Specifies a customization specification you want to apply to the virtual machine. This works only in 32-bit mode.
optional RunAsync SwitchParameter named
Indicates that the command returns immediately without waiting for the task to complete. In this mode, the output of the cmdlet is a Task object. For more information about the RunAsync parameter, run "help About_RunAsync" in the VMware PowerCLI console.
optional SEVEnabled Boolean named
Specifies whether SEV (Secure Encrypted Virtualization) is enabled or not. It allows the CPU to encrypt the memory and the state of the virtual machine. It is applicable for AMD CPUs only.
optional Server VIServer[] named
Specifies the vCenter Server systems on which you want to run the cmdlet. If no value is provided or $null value is passed to this parameter, the command runs on the default servers. For more information about default servers, see the description of the Connect-VIServer cmdlet.
optional VMSwapFilePolicy VMSwapfilePolicy named
Specifies the swapfile placement policy. The following values are valid: InHostDataStore - stores the swapfile in the datastore specified by the VMSwapfileDatastoreID property of the virtual machine host. If the VMSwapfileDatastoreID property is not set or indicates a datastore with insufficient free space, the swapfile is stored in the same directory as the virtual machine. This setting might degrade the vMotion performance. WithVM - stores the swapfile in the same directory as the virtual machine.
optional Version VMVersion named
This parameter is deprecated. Use the HardwareVersion parameter instead. Specifies the version to which you want to upgrade the virtual machine. The valid values are v4, v7, v8, v9, v10, v11, v12, v13, and v14. You cannot downgrade to an earlier version.
Set-VM
[-KeyProvider < KeyProvider > ]
[-RunAsync ]
[-Server < VIServer[] > ]
[-SkipHardDisks ]
[-StoragePolicy < StoragePolicy > ]
[CommonParameters]

Parameters

Required Parameter Name Type Position Features Description
required
VM VirtualMachine[] named
  • pipeline
Specifies the virtual machine that you want to configure.
optional KeyProvider KeyProvider named
Specifies the key provider that you want to use for the encryption key while encrypting the specified virtual machine. If StoragePolicy is not specified, the default encryption storage policy "VM Encryption Policy" is used.
optional RunAsync SwitchParameter named
Indicates that the command returns immediately without waiting for the task to complete. In this mode, the output of the cmdlet is a Task object. For more information about the RunAsync parameter, run "help About_RunAsync" in the VMware PowerCLI console.
optional Server VIServer[] named
Specifies the vCenter Server systems on which you want to run the cmdlet. If no value is provided or $null value is passed to this parameter, the command runs on the default servers. For more information about default servers, see the description of the Connect-VIServer cmdlet.
optional SkipHardDisks SwitchParameter named
Indicates that the StoragePolicy or encryption (KeyProvider) is applied to vmhome only.
optional StoragePolicy StoragePolicy named
Specifies the StoragePolicy that you want to attach to the specified virtual machine. If the StoragePolicy is an encryption policy, the virtual machine is encrypted. Otherwise, the virtual machine is decrypted, if it's encrypted before the cmdlet, and attached with the new StoragePolicy.
Set-VM
[-PromoteDisks ]
[-RunAsync ]
[-Server < VIServer[] > ]
[CommonParameters]

Parameters

Required Parameter Name Type Position Features Description
required
VM VirtualMachine[] named
  • pipeline
Specifies the virtual machine that you want to configure.
optional PromoteDisks SwitchParameter named
Promotes virtual machine disks. You can use this parameter to promote a linked clone virtual machine to a full clone.
optional RunAsync SwitchParameter named
Indicates that the command returns immediately without waiting for the task to complete. In this mode, the output of the cmdlet is a Task object. For more information about the RunAsync parameter, run "help About_RunAsync" in the VMware PowerCLI console.
optional Server VIServer[] named
Specifies the vCenter Server systems on which you want to run the cmdlet. If no value is provided or $null value is passed to this parameter, the command runs on the default servers. For more information about default servers, see the description of the Connect-VIServer cmdlet.
Set-VM
[-DrsAutomationLevel < DrsAutomationLevel > ]
[-HAIsolationResponse < HAIsolationResponse > ]
[-HARestartPriority < HARestartPriority > ]
[-Name < String > ]
[-OSCustomizationSpec < OSCustomizationSpec > ]
[-RunAsync ]
[-Server < VIServer[] > ]
[-Snapshot < Snapshot > ]
[-VMSwapFilePolicy < VMSwapfilePolicy > ]
[CommonParameters]

Parameters

Required Parameter Name Type Position Features Description
required
VM VirtualMachine[] named
  • pipeline
Specifies the virtual machine that you want to configure.
optional DrsAutomationLevel DrsAutomationLevel named
Specifies a Distributed Resource Scheduler (DRS) automation level. The valid values are FullyAutomated, Manual, PartiallyAutomated, AsSpecifiedByCluster, and Disabled. Passing values to this parameter through a pipeline is deprecated and will be deactivated in a future release. Specifying this parameter is only supported when the virtual machine is inside a cluster. Otherwise, an error appears.
optional HAIsolationResponse HAIsolationResponse named
Indicates whether the virtual machine should be powered off if a host determines that it's isolated from the rest of the compute resource. The valid values are AsSpecifiedByCluster, PowerOff, and DoNothing. Passing values to this parameter through a pipeline is deprecated and will be deactivated in a future release. Specifying this parameter is only supported when the virtual machine is inside a cluster. Otherwise, an error appears.
optional HARestartPriority HARestartPriority named
Specifies the virtual machine High Availability (HA) restart priority. The valid values are Disabled, Lowest, Low, Medium, High, Highest and ClusterRestartPriority. VMware HA is a feature that detects failed virtual machines and automatically restarts them on alternative ESX hosts. Passing values to this parameter through a pipeline is deprecated and will be deactivated in a future release. Specifying this parameter is only supported when the virtual machine is inside a cluster. Otherwise, an error appears.
optional Name String named
Specifies a new name for the virtual machine.
optional OSCustomizationSpec OSCustomizationSpec named
Specifies a customization specification you want to apply to the virtual machine. This works only in 32-bit mode.
optional RunAsync SwitchParameter named
Indicates that the command returns immediately without waiting for the task to complete. In this mode, the output of the cmdlet is a Task object. For more information about the RunAsync parameter, run "help About_RunAsync" in the VMware PowerCLI console.
optional Server VIServer[] named
Specifies the vCenter Server systems on which you want to run the cmdlet. If no value is provided or $null value is passed to this parameter, the command runs on the default servers. For more information about default servers, see the description of the Connect-VIServer cmdlet.
optional Snapshot Snapshot named
  • pipeline
Specifies a snapshot whose state you want to apply to the virtual machine.
optional VMSwapFilePolicy VMSwapfilePolicy named
Specifies the swapfile placement policy. The following values are valid: InHostDataStore - stores the swapfile in the datastore specified by the VMSwapfileDatastoreID property of the virtual machine host. If the VMSwapfileDatastoreID property is not set or indicates a datastore with insufficient free space, the swapfile is stored in the same directory as the virtual machine. This setting might degrade the vMotion performance. WithVM - stores the swapfile in the same directory as the virtual machine.
Set-VM
[-Name < String > ]
[-RunAsync ]
[-Server < VIServer[] > ]
[-ToTemplate ]
[CommonParameters]

Parameters

Required Parameter Name Type Position Features Description
required
VM VirtualMachine[] named
  • pipeline
Specifies the virtual machine that you want to configure.
optional Name String named
Specifies a new name for the virtual machine.
optional RunAsync SwitchParameter named
Indicates that the command returns immediately without waiting for the task to complete. In this mode, the output of the cmdlet is a Task object. For more information about the RunAsync parameter, run "help About_RunAsync" in the VMware PowerCLI console.
optional Server VIServer[] named
Specifies the vCenter Server systems on which you want to run the cmdlet. If no value is provided or $null value is passed to this parameter, the command runs on the default servers. For more information about default servers, see the description of the Connect-VIServer cmdlet.
optional ToTemplate SwitchParameter named
Indicates that you want to convert the virtual machine to a template.

Output

VMware.VimAutomation.ViCore.Types.V1.Inventory.VirtualMachine

Examples

Example 1

$template = Get-VM VM | Set-VM -ToTemplate -Name VMTemplate

Converts the VM virtual machine to a template and stores the template in the $template variable.

Example 2

Get-VM -Location ResourcePool01 | Set-VM -MemoryGB 2 -NumCPU 2

Upgrades the memory and CPU count of the virtual machines in ResourcePool01.

Example 3

Set-VM -VM VM -HardwareVersion vmx-07

Upgrades the virtual hardware version of the VM virtual machine.

Example 4

$snapshot = Get-Snapshot -VM $vm -Name "Initial state"

Set-VM -VM $vm -Snapshot $snapshot

Reverts the VM virtual machine to the "Initial state" snapshot.

Example 5

$spec = Get-OSCustomizationSpec -Name FinanceDepartmentSpec;

Set-VM -VM $vm -OSCustomizationSpec $spec

Applies a customization specification on the specified virtual machines.

Example 6

Set-VM $vm -Name "Web Server" -GuestID winNetStandardGuest -Description "Company's web server"

Changes the name, description, and guest ID of the specified virtual machine.

Example 7

$keyprovider = Get-KeyProvider | select -first 1
Set-VM $vm -KeyProvider $keyprovider

Encrypts the whole virtual machine stored in $vm including its VM Home and all its valid hard disks.

Example 8

$storagepolicy = Get-SpbmStoragePolicy | select -first 1
Set-VM $vm -StoragePolicy $storagepolicy -SkipHardDisks

Attaches the $storagepolicy to the VM Home of the $vm virtual machine: - If the $storagepolicy is an encryption policy, the VM Home of the $vm virtual machine is encrypted or re-encrypted with the new policy.

Example 9

Set-VM $vm -DisableEncryption

Decrypts the whole virtual machine stored in $vm including its VM Home and all its valid hard disks.

Example 10

$vm = Get-VM -Name MyVM1
Set-VM -VM $vm -SEVEnabled $true

Enables SEV (Secure Encrypted Virtualization) for the MyVM1 virtual machine.

Example 11

$vm = Get-VM -Name MyVM1
Set-VM -VM $vm -BootDelayMillisecond 10000

Modifies the 'MyVM1' virtual machine and sets the boot delay between the virtual machine power on or restart and the beginning of the boot sequence to 10000 milliseconds.

Related Commands

VM

This cmdlet retrieves the virtual machines on a vCenter Server system.

This cmdlet moves virtual machines to another location.

This cmdlet creates a new virtual machine.

This cmdlet removes the specified virtual machines from the vCenter Server system.

This cmdlet restarts the specified virtual machines.

This cmdlet modifies the configuration of the virtual machine.

This cmdlet powers on virtual machines.

This cmdlet powers off virtual machines.

This cmdlet suspends virtual machines.

This cmdlet unlocks the specified virtual machine.

VMConsoleWindow

This cmdlet opens a window to the virtual machine's console.

VMGuest

This cmdlet retrieves the guest operating systems of the specified virtual machines.

This cmdlet restarts the virtual machine guest operating systems.

This cmdlet shuts down the specified virtual machine guest OS.

This cmdlet suspends the specified guest operating systems.

VMGuestDisk

This cmdlet retrieves storage volumes as seen by the virtual machines' guest operating systems.

VMGuestFile

This cmdlet copies files and folders from and to the guest OS of the specified virtual machines using VMware Tools.

VMQuestion

This cmdlet retrieves the pending questions for the specified virtual machines.

This cmdlet answers the specified virtual machine question.

VMResourceConfiguration

This cmdlet retrieves information about the resource allocation between the selected virtual machines.

This cmdlet configures resource allocation between the virtual machines.

VMScript

This cmdlet runs a script in the guest OS of each of the specified virtual machines.

VMStartPolicy

This cmdlet retrieves the start policy of the virtual machines on a vCenter Server system.

This cmdlet modifies the virtual machine start policy.