add 1 property and 1 function for vMotionEncryption

This commit is contained in:
yangm
2016-12-20 19:41:59 -08:00
parent ce69869e8a
commit 7d49541a25

View File

@@ -249,7 +249,7 @@ Function Set-vMotionEncryptionConfig {
.PARAMETER Encryption .PARAMETER Encryption
Specifies the value you want to set to the vMotionEncryption property. Specifies the value you want to set to the vMotionEncryption property.
The Encryption options are: Disabled, Opportunistic, and Required. The Encryption options are: disabled, opportunistic, and required.
.EXAMPLE .EXAMPLE
PS C:\> Get-VM | Set-vMotionEncryptionConfig -Encryption opportunistic PS C:\> Get-VM | Set-vMotionEncryptionConfig -Encryption opportunistic
@@ -257,8 +257,8 @@ Function Set-vMotionEncryptionConfig {
Sets the vMotionEncryption of all the VMs Sets the vMotionEncryption of all the VMs
.NOTES .NOTES
Author : Carrie Yang Author : Brian Graf, Carrie Yang.
Author email : yangm@vmware.com Author email : grafb@vmware.com, yangm@vmware.com
Version : 1.0 Version : 1.0
==========Tested Against Environment========== ==========Tested Against Environment==========
@@ -274,23 +274,26 @@ Function Set-vMotionEncryptionConfig {
[Parameter(Mandatory=$True,ValueFromPipeline=$True,ValueFromPipelinebyPropertyName=$True)] [Parameter(Mandatory=$True,ValueFromPipeline=$True,ValueFromPipelinebyPropertyName=$True)]
[VMware.VimAutomation.ViCore.Types.V1.Inventory.VirtualMachine]$VM, [VMware.VimAutomation.ViCore.Types.V1.Inventory.VirtualMachine]$VM,
[Parameter(Mandatory=$True]
[ValidateSet("disabled", "opportunistic", "required")] [ValidateSet("disabled", "opportunistic", "required")]
[String]$Encryption [String]$Encryption
) )
process{ process{
# Confirm the connected VIServer is vCenter Server if ($VM.vMotionEncryption -eq $Encryption) {
ConfirmIsVCenter Write-Warning "The encrypted vMotion state is already $Encrypted, no need to change it."
return
}
if ($VM.Encrypted -and $VM.vMotionEncryption -ne $Encryption) { if ($VM.Encrypted) {
Write-Error "Cannot change encrypted vMotion state for an encrypted VM." Write-Error "Cannot change encrypted vMotion state for an encrypted VM."
return return
} }
$VMView = $VM | get-view $VMView = $VM | get-view
$config = new-object VMware.Vim.VirtualMachineConfigSpec $Config = New-Object VMware.Vim.VirtualMachineConfigSpec
$config.MigrateEncryption = New-object VMware.Vim.VirtualMachineConfigSpecEncryptedVMotionModes $Config.MigrateEncryption = New-Object VMware.Vim.VirtualMachineConfigSpecEncryptedVMotionModes
$config.MigrateEncryption = "$encryption" $Config.MigrateEncryption = $Encryption
$VMView.ReconfigVM($config) $VMView.ReconfigVM($config)