From c265c504470d933052eb4028a094fa0405600c85 Mon Sep 17 00:00:00 2001 From: Jose Rodriguez Date: Sun, 8 Apr 2018 15:00:08 -0700 Subject: [PATCH 01/22] Adding Remove-HVMachine function --- .../VMware.Hv.Helper/VMware.HV.Helper.psm1 | 173 +++++++++++++++++- 1 file changed, 172 insertions(+), 1 deletion(-) diff --git a/Modules/VMware.Hv.Helper/VMware.HV.Helper.psm1 b/Modules/VMware.Hv.Helper/VMware.HV.Helper.psm1 index 0f9a2f9..9eaeae4 100644 --- a/Modules/VMware.Hv.Helper/VMware.HV.Helper.psm1 +++ b/Modules/VMware.Hv.Helper/VMware.HV.Helper.psm1 @@ -9990,4 +9990,175 @@ function Reset-HVMachine { } } -Export-ModuleMember Add-HVDesktop,Add-HVRDSServer,Connect-HVEvent,Disconnect-HVEvent,Get-HVPoolSpec,Get-HVInternalName, Get-HVEvent,Get-HVFarm,Get-HVFarmSummary,Get-HVPool,Get-HVPoolSummary,Get-HVMachine,Get-HVMachineSummary,Get-HVQueryResult,Get-HVQueryFilter,New-HVFarm,New-HVPool,Remove-HVFarm,Remove-HVPool,Set-HVFarm,Set-HVPool,Start-HVFarm,Start-HVPool,New-HVEntitlement,Get-HVEntitlement,Remove-HVEntitlement, Set-HVMachine, New-HVGlobalEntitlement, Remove-HVGlobalEntitlement, Get-HVGlobalEntitlement, Set-HVApplicationIcon, Remove-HVApplicationIcon, Get-HVGlobalSettings, Set-HVGlobalSettings, Set-HVGlobalEntitlement, Get-HVResourceStructure, Get-hvlocalsession, Get-HVGlobalSession, Reset-HVMachine +function Remove-HVMachine(){ + <# + .Synopsis + Remove a Horizon View desktop or desktops. + + .DESCRIPTION + Deletes a VM or an array of VM's from Horizon. Utilizes an Or query filter to match machine names. + + .PARAMETER HVServer + The Horizon server where the machine to be deleted resides.Parameter is not mandatory, + but if you do not specify the server, than make sure you are connected to a Horizon server + first with connect-hvserver. + + .PARAMETER MachineName + The name or names of the machine(s) to be deleted. This is a mandatory parameter. + + .EXAMPLE + remove-HVMachine -HVServer 'horizonserver123' -MachineNames 'LAX-WIN10-002' + Deletes VM 'LAX-WIN10-002' from HV Server 'horizonserver123' + + .EXAMPLE + remove-HVMachine -HVServer 'horizonserver123' -MachineNames $machines + Deletes VM's contained within an array of machine names from HV Server 'horizonserver123' + + .NOTES + Author : Jose Rodriguez + Author email : jrodsguitar@gmail.com + Version : 1.0 + + ===Tested Against Environment==== + Horizon View Server Version : 7.1.1 + PowerCLI Version : PowerCLI 6.5, PowerCLI 6.5.1 + PowerShell Version : 5.0 + #> + + [CmdletBinding( + SupportsShouldProcess = $true, + ConfirmImpact = 'High' + )] + + param( + + [Parameter(Mandatory = $true)] + [array] + $MachineNames, + + [Parameter(Mandatory = $false)] + $HVServer + ) + +if($HVServer){ + + $hvapi = ($global:DefaultHVServers| where {$_.name -imatch $HVServer }).extensiondata + +} + +else { + + $hvapi = $global:DefaultHVServers.ExtensionData + +} + +#Connect to Query Service +$queryService = New-Object 'Vmware.Hv.QueryServiceService' +#QUery Definition +$queryDefinition = New-Object 'Vmware.Hv.QueryDefinition' +#Query Filter +$queryDefinition.queryEntityType = 'MachineNamesView' + +#Create Filter Set so we can populate it with QueryFilterEquals data +[VMware.Hv.queryfilter[]]$filterSet = @() +foreach($machine in $machineNames){ + + #queryfilter values + $queryFilterEquals = New-Object VMware.Hv.QueryFilterEquals + $queryFilterEquals.memberName = "base.name" + $queryFilterEquals.value = "$machine" + + $filterSet += $queryFilterEquals + +} + +#Or Filter +$orFilter = New-Object VMware.Hv.QueryFilterOr +$orFilter.filters = $filterSet + +#Set Definition filter to value of $orfilter +$queryDefinition.filter = $orFilter + +#Retrieve query results. Returns all machines to be deleted +$queryResults = $queryService.QueryService_Query($hvapi,$queryDefinition) + +#Assign VM Object to variable +$deleteThisMachine = $queryResults.Results + +#Machine Service +$machineService = new-object VMware.Hv.MachineService + +#Get Machine Service machine object +$deleteMachine = $machineService.Machine_GetInfos($hvapi,$deleteThisMachine.Id) + +#If sessions exist on the machines we are going to delete than force kill those sessions. +#The deleteMachines method will not work if there are any existing sessions so this step is very important. +write-host "Attemtping log off of machines" + +if($deleteMachine.base.session.id){ +$trys = 0 + + do{ + foreach($session in $deleteMachine.base.session){ + + $sessions = $null + [VMware.Hv.SessionId[]]$sessions += $session + + } + + try{ + + write-host "`n" + write-host "Attemtping log off of machines" + write-host "`n" + $logOffSession = new-object 'VMware.Hv.SessionService' + $logOffSession.Session_LogoffSessionsForced($hvapi,$sessions) + + #Wait more for Sessions to end + + Start-Sleep -Seconds 5 + + } + + catch{ + + Write-Host "Attempted to Log Off Sessions from below machines but recieved an error. This doesn't usually mean it failed. Typically the session is succesfully logged off but takes some time" + write-host "`n" + write-host ($deleteMachine.base.Name -join "`n") + + start-sleep -seconds 5 + + } + + if(($trys -le 10)){ + + write-host "`n" + write-host "Retrying Logoffs: $trys times" + #Recheck existing sessions + $deleteMachine = $machineService.Machine_GetInfos($hvapi,$deleteThisMachine.Id) + + } + + $trys++ + + } + + until((!$deleteMachine.base.session.id) -or ($trys -gt 10)) + +} + +#Create delete spec for the DeleteMachines method +$deleteSpec = [VMware.Hv.MachineDeleteSpec]::new() +$deleteSpec.DeleteFromDisk = $true +$deleteSpec.ArchivePersistentDisk = $false + +#Delete VM +write-host "Deleting:" +Write-Output $($deleteMachine.base.Name) + +#Delete the machines +$bye = $machineService.Machine_DeleteMachines($hvapi,$deleteMachine.id,$deleteSpec) + +} + +Export-ModuleMember Add-HVDesktop,Add-HVRDSServer,Connect-HVEvent,Disconnect-HVEvent,Get-HVPoolSpec,Get-HVInternalName, Get-HVEvent,Get-HVFarm,Get-HVFarmSummary,Get-HVPool,Get-HVPoolSummary,Get-HVMachine,Get-HVMachineSummary,Get-HVQueryResult,Get-HVQueryFilter,New-HVFarm,New-HVPool,Remove-HVFarm,Remove-HVPool,Set-HVFarm,Set-HVPool,Start-HVFarm,Start-HVPool,New-HVEntitlement,Get-HVEntitlement,Remove-HVEntitlement, Set-HVMachine, New-HVGlobalEntitlement, Remove-HVGlobalEntitlement, Get-HVGlobalEntitlement, Set-HVApplicationIcon, Remove-HVApplicationIcon, Get-HVGlobalSettings, Set-HVGlobalSettings, Set-HVGlobalEntitlement, Get-HVResourceStructure, Get-hvlocalsession, Get-HVGlobalSession, Reset-HVMachine, Remove-HVMachine From cdff3035cc0a61a6d0e71ab3ee5d41dabc117a1b Mon Sep 17 00:00:00 2001 From: Jose Rodriguez Date: Sun, 8 Apr 2018 20:46:38 -0700 Subject: [PATCH 02/22] Revert "Adding Remove-HVMachine function" This reverts commit c265c504470d933052eb4028a094fa0405600c85. --- .../VMware.Hv.Helper/VMware.HV.Helper.psm1 | 173 +----------------- 1 file changed, 1 insertion(+), 172 deletions(-) diff --git a/Modules/VMware.Hv.Helper/VMware.HV.Helper.psm1 b/Modules/VMware.Hv.Helper/VMware.HV.Helper.psm1 index 9eaeae4..0f9a2f9 100644 --- a/Modules/VMware.Hv.Helper/VMware.HV.Helper.psm1 +++ b/Modules/VMware.Hv.Helper/VMware.HV.Helper.psm1 @@ -9990,175 +9990,4 @@ function Reset-HVMachine { } } -function Remove-HVMachine(){ - <# - .Synopsis - Remove a Horizon View desktop or desktops. - - .DESCRIPTION - Deletes a VM or an array of VM's from Horizon. Utilizes an Or query filter to match machine names. - - .PARAMETER HVServer - The Horizon server where the machine to be deleted resides.Parameter is not mandatory, - but if you do not specify the server, than make sure you are connected to a Horizon server - first with connect-hvserver. - - .PARAMETER MachineName - The name or names of the machine(s) to be deleted. This is a mandatory parameter. - - .EXAMPLE - remove-HVMachine -HVServer 'horizonserver123' -MachineNames 'LAX-WIN10-002' - Deletes VM 'LAX-WIN10-002' from HV Server 'horizonserver123' - - .EXAMPLE - remove-HVMachine -HVServer 'horizonserver123' -MachineNames $machines - Deletes VM's contained within an array of machine names from HV Server 'horizonserver123' - - .NOTES - Author : Jose Rodriguez - Author email : jrodsguitar@gmail.com - Version : 1.0 - - ===Tested Against Environment==== - Horizon View Server Version : 7.1.1 - PowerCLI Version : PowerCLI 6.5, PowerCLI 6.5.1 - PowerShell Version : 5.0 - #> - - [CmdletBinding( - SupportsShouldProcess = $true, - ConfirmImpact = 'High' - )] - - param( - - [Parameter(Mandatory = $true)] - [array] - $MachineNames, - - [Parameter(Mandatory = $false)] - $HVServer - ) - -if($HVServer){ - - $hvapi = ($global:DefaultHVServers| where {$_.name -imatch $HVServer }).extensiondata - -} - -else { - - $hvapi = $global:DefaultHVServers.ExtensionData - -} - -#Connect to Query Service -$queryService = New-Object 'Vmware.Hv.QueryServiceService' -#QUery Definition -$queryDefinition = New-Object 'Vmware.Hv.QueryDefinition' -#Query Filter -$queryDefinition.queryEntityType = 'MachineNamesView' - -#Create Filter Set so we can populate it with QueryFilterEquals data -[VMware.Hv.queryfilter[]]$filterSet = @() -foreach($machine in $machineNames){ - - #queryfilter values - $queryFilterEquals = New-Object VMware.Hv.QueryFilterEquals - $queryFilterEquals.memberName = "base.name" - $queryFilterEquals.value = "$machine" - - $filterSet += $queryFilterEquals - -} - -#Or Filter -$orFilter = New-Object VMware.Hv.QueryFilterOr -$orFilter.filters = $filterSet - -#Set Definition filter to value of $orfilter -$queryDefinition.filter = $orFilter - -#Retrieve query results. Returns all machines to be deleted -$queryResults = $queryService.QueryService_Query($hvapi,$queryDefinition) - -#Assign VM Object to variable -$deleteThisMachine = $queryResults.Results - -#Machine Service -$machineService = new-object VMware.Hv.MachineService - -#Get Machine Service machine object -$deleteMachine = $machineService.Machine_GetInfos($hvapi,$deleteThisMachine.Id) - -#If sessions exist on the machines we are going to delete than force kill those sessions. -#The deleteMachines method will not work if there are any existing sessions so this step is very important. -write-host "Attemtping log off of machines" - -if($deleteMachine.base.session.id){ -$trys = 0 - - do{ - foreach($session in $deleteMachine.base.session){ - - $sessions = $null - [VMware.Hv.SessionId[]]$sessions += $session - - } - - try{ - - write-host "`n" - write-host "Attemtping log off of machines" - write-host "`n" - $logOffSession = new-object 'VMware.Hv.SessionService' - $logOffSession.Session_LogoffSessionsForced($hvapi,$sessions) - - #Wait more for Sessions to end - - Start-Sleep -Seconds 5 - - } - - catch{ - - Write-Host "Attempted to Log Off Sessions from below machines but recieved an error. This doesn't usually mean it failed. Typically the session is succesfully logged off but takes some time" - write-host "`n" - write-host ($deleteMachine.base.Name -join "`n") - - start-sleep -seconds 5 - - } - - if(($trys -le 10)){ - - write-host "`n" - write-host "Retrying Logoffs: $trys times" - #Recheck existing sessions - $deleteMachine = $machineService.Machine_GetInfos($hvapi,$deleteThisMachine.Id) - - } - - $trys++ - - } - - until((!$deleteMachine.base.session.id) -or ($trys -gt 10)) - -} - -#Create delete spec for the DeleteMachines method -$deleteSpec = [VMware.Hv.MachineDeleteSpec]::new() -$deleteSpec.DeleteFromDisk = $true -$deleteSpec.ArchivePersistentDisk = $false - -#Delete VM -write-host "Deleting:" -Write-Output $($deleteMachine.base.Name) - -#Delete the machines -$bye = $machineService.Machine_DeleteMachines($hvapi,$deleteMachine.id,$deleteSpec) - -} - -Export-ModuleMember Add-HVDesktop,Add-HVRDSServer,Connect-HVEvent,Disconnect-HVEvent,Get-HVPoolSpec,Get-HVInternalName, Get-HVEvent,Get-HVFarm,Get-HVFarmSummary,Get-HVPool,Get-HVPoolSummary,Get-HVMachine,Get-HVMachineSummary,Get-HVQueryResult,Get-HVQueryFilter,New-HVFarm,New-HVPool,Remove-HVFarm,Remove-HVPool,Set-HVFarm,Set-HVPool,Start-HVFarm,Start-HVPool,New-HVEntitlement,Get-HVEntitlement,Remove-HVEntitlement, Set-HVMachine, New-HVGlobalEntitlement, Remove-HVGlobalEntitlement, Get-HVGlobalEntitlement, Set-HVApplicationIcon, Remove-HVApplicationIcon, Get-HVGlobalSettings, Set-HVGlobalSettings, Set-HVGlobalEntitlement, Get-HVResourceStructure, Get-hvlocalsession, Get-HVGlobalSession, Reset-HVMachine, Remove-HVMachine +Export-ModuleMember Add-HVDesktop,Add-HVRDSServer,Connect-HVEvent,Disconnect-HVEvent,Get-HVPoolSpec,Get-HVInternalName, Get-HVEvent,Get-HVFarm,Get-HVFarmSummary,Get-HVPool,Get-HVPoolSummary,Get-HVMachine,Get-HVMachineSummary,Get-HVQueryResult,Get-HVQueryFilter,New-HVFarm,New-HVPool,Remove-HVFarm,Remove-HVPool,Set-HVFarm,Set-HVPool,Start-HVFarm,Start-HVPool,New-HVEntitlement,Get-HVEntitlement,Remove-HVEntitlement, Set-HVMachine, New-HVGlobalEntitlement, Remove-HVGlobalEntitlement, Get-HVGlobalEntitlement, Set-HVApplicationIcon, Remove-HVApplicationIcon, Get-HVGlobalSettings, Set-HVGlobalSettings, Set-HVGlobalEntitlement, Get-HVResourceStructure, Get-hvlocalsession, Get-HVGlobalSession, Reset-HVMachine From 245cacae25d0505ece95b8e84fbca3d72de83a46 Mon Sep 17 00:00:00 2001 From: Jose Rodriguez Date: Sun, 8 Apr 2018 20:48:30 -0700 Subject: [PATCH 03/22] Revert "Revert "Adding Remove-HVMachine function"" This reverts commit cdff3035cc0a61a6d0e71ab3ee5d41dabc117a1b. --- .../VMware.Hv.Helper/VMware.HV.Helper.psm1 | 173 +++++++++++++++++- 1 file changed, 172 insertions(+), 1 deletion(-) diff --git a/Modules/VMware.Hv.Helper/VMware.HV.Helper.psm1 b/Modules/VMware.Hv.Helper/VMware.HV.Helper.psm1 index 0f9a2f9..9eaeae4 100644 --- a/Modules/VMware.Hv.Helper/VMware.HV.Helper.psm1 +++ b/Modules/VMware.Hv.Helper/VMware.HV.Helper.psm1 @@ -9990,4 +9990,175 @@ function Reset-HVMachine { } } -Export-ModuleMember Add-HVDesktop,Add-HVRDSServer,Connect-HVEvent,Disconnect-HVEvent,Get-HVPoolSpec,Get-HVInternalName, Get-HVEvent,Get-HVFarm,Get-HVFarmSummary,Get-HVPool,Get-HVPoolSummary,Get-HVMachine,Get-HVMachineSummary,Get-HVQueryResult,Get-HVQueryFilter,New-HVFarm,New-HVPool,Remove-HVFarm,Remove-HVPool,Set-HVFarm,Set-HVPool,Start-HVFarm,Start-HVPool,New-HVEntitlement,Get-HVEntitlement,Remove-HVEntitlement, Set-HVMachine, New-HVGlobalEntitlement, Remove-HVGlobalEntitlement, Get-HVGlobalEntitlement, Set-HVApplicationIcon, Remove-HVApplicationIcon, Get-HVGlobalSettings, Set-HVGlobalSettings, Set-HVGlobalEntitlement, Get-HVResourceStructure, Get-hvlocalsession, Get-HVGlobalSession, Reset-HVMachine +function Remove-HVMachine(){ + <# + .Synopsis + Remove a Horizon View desktop or desktops. + + .DESCRIPTION + Deletes a VM or an array of VM's from Horizon. Utilizes an Or query filter to match machine names. + + .PARAMETER HVServer + The Horizon server where the machine to be deleted resides.Parameter is not mandatory, + but if you do not specify the server, than make sure you are connected to a Horizon server + first with connect-hvserver. + + .PARAMETER MachineName + The name or names of the machine(s) to be deleted. This is a mandatory parameter. + + .EXAMPLE + remove-HVMachine -HVServer 'horizonserver123' -MachineNames 'LAX-WIN10-002' + Deletes VM 'LAX-WIN10-002' from HV Server 'horizonserver123' + + .EXAMPLE + remove-HVMachine -HVServer 'horizonserver123' -MachineNames $machines + Deletes VM's contained within an array of machine names from HV Server 'horizonserver123' + + .NOTES + Author : Jose Rodriguez + Author email : jrodsguitar@gmail.com + Version : 1.0 + + ===Tested Against Environment==== + Horizon View Server Version : 7.1.1 + PowerCLI Version : PowerCLI 6.5, PowerCLI 6.5.1 + PowerShell Version : 5.0 + #> + + [CmdletBinding( + SupportsShouldProcess = $true, + ConfirmImpact = 'High' + )] + + param( + + [Parameter(Mandatory = $true)] + [array] + $MachineNames, + + [Parameter(Mandatory = $false)] + $HVServer + ) + +if($HVServer){ + + $hvapi = ($global:DefaultHVServers| where {$_.name -imatch $HVServer }).extensiondata + +} + +else { + + $hvapi = $global:DefaultHVServers.ExtensionData + +} + +#Connect to Query Service +$queryService = New-Object 'Vmware.Hv.QueryServiceService' +#QUery Definition +$queryDefinition = New-Object 'Vmware.Hv.QueryDefinition' +#Query Filter +$queryDefinition.queryEntityType = 'MachineNamesView' + +#Create Filter Set so we can populate it with QueryFilterEquals data +[VMware.Hv.queryfilter[]]$filterSet = @() +foreach($machine in $machineNames){ + + #queryfilter values + $queryFilterEquals = New-Object VMware.Hv.QueryFilterEquals + $queryFilterEquals.memberName = "base.name" + $queryFilterEquals.value = "$machine" + + $filterSet += $queryFilterEquals + +} + +#Or Filter +$orFilter = New-Object VMware.Hv.QueryFilterOr +$orFilter.filters = $filterSet + +#Set Definition filter to value of $orfilter +$queryDefinition.filter = $orFilter + +#Retrieve query results. Returns all machines to be deleted +$queryResults = $queryService.QueryService_Query($hvapi,$queryDefinition) + +#Assign VM Object to variable +$deleteThisMachine = $queryResults.Results + +#Machine Service +$machineService = new-object VMware.Hv.MachineService + +#Get Machine Service machine object +$deleteMachine = $machineService.Machine_GetInfos($hvapi,$deleteThisMachine.Id) + +#If sessions exist on the machines we are going to delete than force kill those sessions. +#The deleteMachines method will not work if there are any existing sessions so this step is very important. +write-host "Attemtping log off of machines" + +if($deleteMachine.base.session.id){ +$trys = 0 + + do{ + foreach($session in $deleteMachine.base.session){ + + $sessions = $null + [VMware.Hv.SessionId[]]$sessions += $session + + } + + try{ + + write-host "`n" + write-host "Attemtping log off of machines" + write-host "`n" + $logOffSession = new-object 'VMware.Hv.SessionService' + $logOffSession.Session_LogoffSessionsForced($hvapi,$sessions) + + #Wait more for Sessions to end + + Start-Sleep -Seconds 5 + + } + + catch{ + + Write-Host "Attempted to Log Off Sessions from below machines but recieved an error. This doesn't usually mean it failed. Typically the session is succesfully logged off but takes some time" + write-host "`n" + write-host ($deleteMachine.base.Name -join "`n") + + start-sleep -seconds 5 + + } + + if(($trys -le 10)){ + + write-host "`n" + write-host "Retrying Logoffs: $trys times" + #Recheck existing sessions + $deleteMachine = $machineService.Machine_GetInfos($hvapi,$deleteThisMachine.Id) + + } + + $trys++ + + } + + until((!$deleteMachine.base.session.id) -or ($trys -gt 10)) + +} + +#Create delete spec for the DeleteMachines method +$deleteSpec = [VMware.Hv.MachineDeleteSpec]::new() +$deleteSpec.DeleteFromDisk = $true +$deleteSpec.ArchivePersistentDisk = $false + +#Delete VM +write-host "Deleting:" +Write-Output $($deleteMachine.base.Name) + +#Delete the machines +$bye = $machineService.Machine_DeleteMachines($hvapi,$deleteMachine.id,$deleteSpec) + +} + +Export-ModuleMember Add-HVDesktop,Add-HVRDSServer,Connect-HVEvent,Disconnect-HVEvent,Get-HVPoolSpec,Get-HVInternalName, Get-HVEvent,Get-HVFarm,Get-HVFarmSummary,Get-HVPool,Get-HVPoolSummary,Get-HVMachine,Get-HVMachineSummary,Get-HVQueryResult,Get-HVQueryFilter,New-HVFarm,New-HVPool,Remove-HVFarm,Remove-HVPool,Set-HVFarm,Set-HVPool,Start-HVFarm,Start-HVPool,New-HVEntitlement,Get-HVEntitlement,Remove-HVEntitlement, Set-HVMachine, New-HVGlobalEntitlement, Remove-HVGlobalEntitlement, Get-HVGlobalEntitlement, Set-HVApplicationIcon, Remove-HVApplicationIcon, Get-HVGlobalSettings, Set-HVGlobalSettings, Set-HVGlobalEntitlement, Get-HVResourceStructure, Get-hvlocalsession, Get-HVGlobalSession, Reset-HVMachine, Remove-HVMachine From 7235de655d3f452d5ad478652d06b65a2e986c4b Mon Sep 17 00:00:00 2001 From: Jose Rodriguez Date: Mon, 9 Apr 2018 01:58:24 -0700 Subject: [PATCH 04/22] Various modifications per feedback. Now using Get-ViewAPIService to connect. Now using $services variable instead of $viewapi. --- .../VMware.Hv.Helper/VMware.HV.Helper.psm1 | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/Modules/VMware.Hv.Helper/VMware.HV.Helper.psm1 b/Modules/VMware.Hv.Helper/VMware.HV.Helper.psm1 index 9eaeae4..ca6a8f4 100644 --- a/Modules/VMware.Hv.Helper/VMware.HV.Helper.psm1 +++ b/Modules/VMware.Hv.Helper/VMware.HV.Helper.psm1 @@ -10003,8 +10003,8 @@ function Remove-HVMachine(){ but if you do not specify the server, than make sure you are connected to a Horizon server first with connect-hvserver. - .PARAMETER MachineName - The name or names of the machine(s) to be deleted. This is a mandatory parameter. + .PARAMETER MachineNames + The name or names of the machine(s) to be deleted. Accepts a single VM or an array of VM names.This is a mandatory parameter. .EXAMPLE remove-HVMachine -HVServer 'horizonserver123' -MachineNames 'LAX-WIN10-002' @@ -10037,7 +10037,7 @@ function Remove-HVMachine(){ $MachineNames, [Parameter(Mandatory = $false)] - $HVServer + $HVServer = $null ) if($HVServer){ @@ -10080,7 +10080,7 @@ $orFilter.filters = $filterSet $queryDefinition.filter = $orFilter #Retrieve query results. Returns all machines to be deleted -$queryResults = $queryService.QueryService_Query($hvapi,$queryDefinition) +$queryResults = $queryService.QueryService_Query($services,$queryDefinition) #Assign VM Object to variable $deleteThisMachine = $queryResults.Results @@ -10089,7 +10089,7 @@ $deleteThisMachine = $queryResults.Results $machineService = new-object VMware.Hv.MachineService #Get Machine Service machine object -$deleteMachine = $machineService.Machine_GetInfos($hvapi,$deleteThisMachine.Id) +$deleteMachine = $machineService.Machine_GetInfos($services,$deleteThisMachine.Id) #If sessions exist on the machines we are going to delete than force kill those sessions. #The deleteMachines method will not work if there are any existing sessions so this step is very important. @@ -10112,7 +10112,7 @@ $trys = 0 write-host "Attemtping log off of machines" write-host "`n" $logOffSession = new-object 'VMware.Hv.SessionService' - $logOffSession.Session_LogoffSessionsForced($hvapi,$sessions) + $logOffSession.Session_LogoffSessionsForced($services,$sessions) #Wait more for Sessions to end @@ -10135,7 +10135,7 @@ $trys = 0 write-host "`n" write-host "Retrying Logoffs: $trys times" #Recheck existing sessions - $deleteMachine = $machineService.Machine_GetInfos($hvapi,$deleteThisMachine.Id) + $deleteMachine = $machineService.Machine_GetInfos($services,$deleteThisMachine.Id) } @@ -10152,12 +10152,12 @@ $deleteSpec = [VMware.Hv.MachineDeleteSpec]::new() $deleteSpec.DeleteFromDisk = $true $deleteSpec.ArchivePersistentDisk = $false -#Delete VM -write-host "Deleting:" -Write-Output $($deleteMachine.base.Name) - #Delete the machines -$bye = $machineService.Machine_DeleteMachines($hvapi,$deleteMachine.id,$deleteSpec) +write-host "Attempting to Delete:" +Write-Output ($deleteMachine.base.Name -join "`n") +$bye = $machineService.Machine_DeleteMachines($services,$deleteMachine.id,$deleteSpec) + +[System.gc]::collect() } From 054d127f128d190b22ea91f093391b7d18cf42e9 Mon Sep 17 00:00:00 2001 From: Jose Rodriguez Date: Mon, 9 Apr 2018 02:04:20 -0700 Subject: [PATCH 05/22] Making sure Get-ViewAPIService is there. --- .../VMware.Hv.Helper/VMware.HV.Helper.psm1 | 20 ++++++++----------- 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/Modules/VMware.Hv.Helper/VMware.HV.Helper.psm1 b/Modules/VMware.Hv.Helper/VMware.HV.Helper.psm1 index ca6a8f4..60e7293 100644 --- a/Modules/VMware.Hv.Helper/VMware.HV.Helper.psm1 +++ b/Modules/VMware.Hv.Helper/VMware.HV.Helper.psm1 @@ -10040,17 +10040,13 @@ function Remove-HVMachine(){ $HVServer = $null ) -if($HVServer){ - - $hvapi = ($global:DefaultHVServers| where {$_.name -imatch $HVServer }).extensiondata - -} - -else { - - $hvapi = $global:DefaultHVServers.ExtensionData - -} +#Connect to HV Server +$services = Get-ViewAPIService -HVServer $HVServer + + if ($null -eq $services) { + Write-Error "Could not retrieve ViewApi services from connection object" + break + } #Connect to Query Service $queryService = New-Object 'Vmware.Hv.QueryServiceService' @@ -10158,7 +10154,7 @@ Write-Output ($deleteMachine.base.Name -join "`n") $bye = $machineService.Machine_DeleteMachines($services,$deleteMachine.id,$deleteSpec) [System.gc]::collect() - + } Export-ModuleMember Add-HVDesktop,Add-HVRDSServer,Connect-HVEvent,Disconnect-HVEvent,Get-HVPoolSpec,Get-HVInternalName, Get-HVEvent,Get-HVFarm,Get-HVFarmSummary,Get-HVPool,Get-HVPoolSummary,Get-HVMachine,Get-HVMachineSummary,Get-HVQueryResult,Get-HVQueryFilter,New-HVFarm,New-HVPool,Remove-HVFarm,Remove-HVPool,Set-HVFarm,Set-HVPool,Start-HVFarm,Start-HVPool,New-HVEntitlement,Get-HVEntitlement,Remove-HVEntitlement, Set-HVMachine, New-HVGlobalEntitlement, Remove-HVGlobalEntitlement, Get-HVGlobalEntitlement, Set-HVApplicationIcon, Remove-HVApplicationIcon, Get-HVGlobalSettings, Set-HVGlobalSettings, Set-HVGlobalEntitlement, Get-HVResourceStructure, Get-hvlocalsession, Get-HVGlobalSession, Reset-HVMachine, Remove-HVMachine From d987a7535b99f804df0b0e4b147e3991bf246bcd Mon Sep 17 00:00:00 2001 From: Markus Kraus Date: Wed, 25 Apr 2018 22:48:38 +0200 Subject: [PATCH 06/22] vCD-Module _Update --- Modules/VMware-vCD-Module/LICENSE | 21 +++ .../VMware-vCD-Module/VMware-vCD-Module.psd1 | 58 +++--- .../functions/Invoke-MyOnBoarding.psm1 | 16 +- .../functions/New-MyEdgeGateway.psm1 | 18 +- .../functions/New-MyOrg.psm1 | 4 +- .../functions/New-MyOrgAdmin.psm1 | 4 +- .../functions/New-MyOrgNetwork.psm1 | 166 ++++++++++++++++++ .../functions/New-MyOrgVdc.psm1 | 59 ++++--- 8 files changed, 275 insertions(+), 71 deletions(-) create mode 100644 Modules/VMware-vCD-Module/LICENSE create mode 100644 Modules/VMware-vCD-Module/functions/New-MyOrgNetwork.psm1 diff --git a/Modules/VMware-vCD-Module/LICENSE b/Modules/VMware-vCD-Module/LICENSE new file mode 100644 index 0000000..0fa220a --- /dev/null +++ b/Modules/VMware-vCD-Module/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2018 Markus Kraus + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/Modules/VMware-vCD-Module/VMware-vCD-Module.psd1 b/Modules/VMware-vCD-Module/VMware-vCD-Module.psd1 index 27584d1..bf67094 100644 --- a/Modules/VMware-vCD-Module/VMware-vCD-Module.psd1 +++ b/Modules/VMware-vCD-Module/VMware-vCD-Module.psd1 @@ -1,5 +1,5 @@ # -# Modulmanifest für das Modul "PSGet_VMware-vCD-Module" +# Modulmanifest f�r das Modul "PSGet_VMware-vCD-Module" # # Generiert von: Markus # @@ -8,52 +8,52 @@ @{ -# Die diesem Manifest zugeordnete Skript- oder Binärmoduldatei. +# Die diesem Manifest zugeordnete Skript- oder Bin�rmoduldatei. # RootModule = '' # Die Versionsnummer dieses Moduls -ModuleVersion = '1.0.0' +ModuleVersion = '1.3.0' # ID zur eindeutigen Kennzeichnung dieses Moduls GUID = '1ef8a2de-ca22-4c88-8cdb-e00f35007d2a' # Autor dieses Moduls -Author = 'Markus' +Author = 'Markus Kraus' # Unternehmen oder Hersteller dieses Moduls CompanyName = 'mycloudrevolution.com' -# Urheberrechtserklärung für dieses Modul +# Urheberrechtserkl�rung f�r dieses Modul Copyright = '(c) 2017 Markus. Alle Rechte vorbehalten.' # Beschreibung der von diesem Modul bereitgestellten Funktionen -# Description = '' +Description = 'This a POwerShell Module based on VMware PowerCLI vCloud Director Module to extend its function' -# Die für dieses Modul mindestens erforderliche Version des Windows PowerShell-Moduls +# Die f�r dieses Modul mindestens erforderliche Version des Windows PowerShell-Moduls # PowerShellVersion = '' -# Der Name des für dieses Modul erforderlichen Windows PowerShell-Hosts +# Der Name des f�r dieses Modul erforderlichen Windows PowerShell-Hosts # PowerShellHostName = '' -# Die für dieses Modul mindestens erforderliche Version des Windows PowerShell-Hosts +# Die f�r dieses Modul mindestens erforderliche Version des Windows PowerShell-Hosts # PowerShellHostVersion = '' -# Die für dieses Modul mindestens erforderliche Microsoft .NET Framework-Version +# Die f�r dieses Modul mindestens erforderliche Microsoft .NET Framework-Version # DotNetFrameworkVersion = '' -# Die für dieses Modul mindestens erforderliche Version der CLR (Common Language Runtime) +# Die f�r dieses Modul mindestens erforderliche Version der CLR (Common Language Runtime) # CLRVersion = '' -# Die für dieses Modul erforderliche Prozessorarchitektur ("Keine", "X86", "Amd64"). +# Die f�r dieses Modul erforderliche Prozessorarchitektur ("Keine", "X86", "Amd64"). # ProcessorArchitecture = '' -# Die Module, die vor dem Importieren dieses Moduls in die globale Umgebung geladen werden müssen -# RequiredModules = @() +# Die Module, die vor dem Importieren dieses Moduls in die globale Umgebung geladen werden m�ssen +RequiredModules = @('VMware.VimAutomation.Cloud') -# Die Assemblys, die vor dem Importieren dieses Moduls geladen werden müssen +# Die Assemblys, die vor dem Importieren dieses Moduls geladen werden m�ssen # RequiredAssemblies = @() -# Die Skriptdateien (PS1-Dateien), die vor dem Importieren dieses Moduls in der Umgebung des Aufrufers ausgeführt werden. +# Die Skriptdateien (PS1-Dateien), die vor dem Importieren dieses Moduls in der Umgebung des Aufrufers ausgef�hrt werden. # ScriptsToProcess = @() # Die Typdateien (.ps1xml), die beim Importieren dieses Moduls geladen werden sollen @@ -63,14 +63,16 @@ Copyright = '(c) 2017 Markus. Alle Rechte vorbehalten.' # FormatsToProcess = @() # Die Module, die als geschachtelte Module des in "RootModule/ModuleToProcess" angegebenen Moduls importiert werden sollen. -NestedModules = @('functions\Invoke-MyOnBoarding.psm1', +NestedModules = @('functions\Invoke-MyOnBoarding.psm1', 'functions\New-MyEdgeGateway.psm1', - 'functions\New-MyOrg.psm1', - 'functions\New-MyOrgAdmin.psm1', - 'functions\New-MyOrgVdc.psm1') + 'functions\New-MyOrg.psm1', + 'functions\New-MyOrgAdmin.psm1', + 'functions\New-MyOrgVdc.psm1', + 'functions\New-MyOrgNetwork.psm1' + ) # Aus diesem Modul zu exportierende Funktionen -FunctionsToExport = 'Invoke-MyOnBoarding', 'New-MyEdgeGateway', 'New-MyOrg', 'New-MyOrgAdmin', 'New-MyOrgVdc' +FunctionsToExport = 'Invoke-MyOnBoarding', 'New-MyEdgeGateway', 'New-MyOrg', 'New-MyOrgAdmin', 'New-MyOrgVdc', 'New-MyOrgNetwork' # Aus diesem Modul zu exportierende Cmdlets CmdletsToExport = '*' @@ -90,28 +92,28 @@ AliasesToExport = '*' # Liste aller Dateien in diesem Modulpaket # FileList = @() -# Die privaten Daten, die an das in "RootModule/ModuleToProcess" angegebene Modul übergeben werden sollen. Diese können auch eine PSData-Hashtabelle mit zusätzlichen von PowerShell verwendeten Modulmetadaten enthalten. +# Die privaten Daten, die an das in "RootModule/ModuleToProcess" angegebene Modul �bergeben werden sollen. Diese k�nnen auch eine PSData-Hashtabelle mit zus�tzlichen von PowerShell verwendeten Modulmetadaten enthalten. PrivateData = @{ PSData = @{ # Tags applied to this module. These help with module discovery in online galleries. - # Tags = @() + Tags = @('VMware', 'vCloud', 'PowerCLI', 'vCloudDirector', 'Automation', 'EdgeGateway', 'OrgNetwork') # A URL to the license for this module. - # LicenseUri = '' + LicenseUri = 'https://github.com/mycloudrevolution/VMware-vCD-Module/blob/master/LICENSE' # A URL to the main website for this project. - # ProjectUri = '' + ProjectUri = 'https://github.com/mycloudrevolution/VMware-vCD-Module' # A URL to an icon representing this module. - # IconUri = '' + IconUri = 'https://github.com/mycloudrevolution/VMware-vCD-Module/blob/master/media/vCD_Small.png' # ReleaseNotes of this module # ReleaseNotes = '' # External dependent modules of this module - # ExternalModuleDependencies = '' + ExternalModuleDependencies = 'VMware.VimAutomation.Cloud' } # End of PSData hashtable @@ -120,7 +122,7 @@ PrivateData = @{ # HelpInfo-URI dieses Moduls # HelpInfoURI = '' -# Standardpräfix für Befehle, die aus diesem Modul exportiert werden. Das Standardpräfix kann mit "Import-Module -Prefix" überschrieben werden. +# Standardpr�fix f�r Befehle, die aus diesem Modul exportiert werden. Das Standardpr�fix kann mit "Import-Module -Prefix" �berschrieben werden. # DefaultCommandPrefix = '' } diff --git a/Modules/VMware-vCD-Module/functions/Invoke-MyOnBoarding.psm1 b/Modules/VMware-vCD-Module/functions/Invoke-MyOnBoarding.psm1 index 97e00ed..4d10fba 100644 --- a/Modules/VMware-vCD-Module/functions/Invoke-MyOnBoarding.psm1 +++ b/Modules/VMware-vCD-Module/functions/Invoke-MyOnBoarding.psm1 @@ -1,6 +1,4 @@ -#Requires -Version 4 -#Requires -Modules VMware.VimAutomation.Cloud, @{ModuleName="VMware.VimAutomation.Cloud";ModuleVersion="6.3.0.0"} -Function Invoke-MyOnBoarding { +Function Invoke-MyOnBoarding { <# .SYNOPSIS Creates all vCD Objecst for a new IAAS Customer @@ -158,18 +156,22 @@ Function Invoke-MyOnBoarding { if ($Configs.OrgVdc.ExternalNetwork -and $Configs.OrgVdc.EdgeGateway -like "Yes"){ Write-Host "Edge Gateway for Org VDC '$($Configs.OrgVdc.Name)' Requested!" - $Trash = New-MyOrgVdc -Name $Configs.OrgVdc.Name -CPULimit $CPULimit -MEMLimit $MEMLimit -StorageLimit $StorageLimit -Networkpool $Configs.OrgVdc.NetworkPool ` -StorageProfile $Configs.OrgVdc.StorageProfile -ProviderVDC $Configs.OrgVdc.ProviderVDC -Org $Configs.Org.Name -Enabled:$Enabled + $Trash = New-MyOrgVdc -Name $Configs.OrgVdc.Name -CPULimit $CPULimit -MEMLimit $MEMLimit -StorageLimit $StorageLimit -Networkpool $Configs.OrgVdc.NetworkPool ` + -StorageProfile $Configs.OrgVdc.StorageProfile -ProviderVDC $Configs.OrgVdc.ProviderVDC -Org $Configs.Org.Name -Enabled:$Enabled $EdgeName = $Configs.Org.Name + "-ESG01" - $Trash = New-MyEdgeGateway -Name $EdgeName -OrgVDCName $Configs.OrgVdc.Name -Orgname $Configs.Org.Name -ExternalNetwork $Configs.OrgVdc.ExternalNetwork ` -IPAddress $Configs.OrgVdc.IPAddress -SubnetMask $Configs.OrgVdc.SubnetMask -Gateway $Configs.OrgVdc.Gateway -IPRangeStart $Configs.OrgVdc.IPRangeStart -IPRangeEnd $Configs.OrgVdc.IPRangeEnd + $Trash = New-MyEdgeGateway -Name $EdgeName -OrgVDCName $Configs.OrgVdc.Name -Orgname $Configs.Org.Name -ExternalNetwork $Configs.OrgVdc.ExternalNetwork ` + -IPAddress $Configs.OrgVdc.IPAddress -SubnetMask $Configs.OrgVdc.SubnetMask -Gateway $Configs.OrgVdc.Gateway -IPRangeStart $Configs.OrgVdc.IPRangeStart -IPRangeEnd $Configs.OrgVdc.IPRangeEnd } elseif ($Configs.OrgVdc.ExternalNetwork -and $Configs.OrgVdc.EdgeGateway -like "No"){ Write-Host "External Network for Org VDC '$($Configs.OrgVdc.Name)' Requested!" - $Trash = New-MyOrgVdc -Name $Configs.OrgVdc.Name -CPULimit $CPULimit -MEMLimit $MEMLimit -StorageLimit $StorageLimit -Networkpool $Configs.OrgVdc.NetworkPool ` -StorageProfile $Configs.OrgVdc.StorageProfile -ProviderVDC $Configs.OrgVdc.ProviderVDC -ExternalNetwork $Configs.OrgVdc.ExternalNetwork -Org $Configs.Org.Name -Enabled:$Enabled + $Trash = New-MyOrgVdc -Name $Configs.OrgVdc.Name -CPULimit $CPULimit -MEMLimit $MEMLimit -StorageLimit $StorageLimit -Networkpool $Configs.OrgVdc.NetworkPool ` + -StorageProfile $Configs.OrgVdc.StorageProfile -ProviderVDC $Configs.OrgVdc.ProviderVDC -ExternalNetwork $Configs.OrgVdc.ExternalNetwork -Org $Configs.Org.Name -Enabled:$Enabled } else { Write-Host "No external Connection for Org VDC '$($Configs.OrgVdc.Name)' Requested!" - $Trash = New-PecOrgVdc -Name $Configs.OrgVdc.Name -CPULimit $CPULimit -MEMLimit $MEMLimit -StorageLimit $StorageLimit -Networkpool $ProVdcNetworkPool.Name ` -StorageProfile $Configs.OrgVdc.StorageProfile -ProviderVDC $Configs.OrgVdc.ProviderVDC -Org $Configs.Org.Name -Enabled:$Enabled + $Trash = New-PecOrgVdc -Name $Configs.OrgVdc.Name -CPULimit $CPULimit -MEMLimit $MEMLimit -StorageLimit $StorageLimit -Networkpool $ProVdcNetworkPool.Name ` + -StorageProfile $Configs.OrgVdc.StorageProfile -ProviderVDC $Configs.OrgVdc.ProviderVDC -Org $Configs.Org.Name -Enabled:$Enabled } Write-Host "$(Get-Date -Format "yyyy-MM-dd HH:mm:ss") Creating new OrgVdc OK" -ForegroundColor Green Get-OrgVdc -Org $Configs.Org.Name -Name $Configs.OrgVdc.Name | Select-Object Name, Enabled, CpuAllocationGhz, MemoryLimitGB, StorageLimitGB, AllocationModel, ThinProvisioned, UseFastProvisioning, ` diff --git a/Modules/VMware-vCD-Module/functions/New-MyEdgeGateway.psm1 b/Modules/VMware-vCD-Module/functions/New-MyEdgeGateway.psm1 index 205c635..dc8d8f8 100644 --- a/Modules/VMware-vCD-Module/functions/New-MyEdgeGateway.psm1 +++ b/Modules/VMware-vCD-Module/functions/New-MyEdgeGateway.psm1 @@ -1,6 +1,4 @@ -#Requires -Version 4 -#Requires -Modules VMware.VimAutomation.Cloud, @{ModuleName="VMware.VimAutomation.Cloud";ModuleVersion="6.3.0.0"} -Function New-MyEdgeGateway { +Function New-MyEdgeGateway { <# .SYNOPSIS Creates a new Edge Gateway with Default Parameters @@ -9,7 +7,6 @@ Function New-MyEdgeGateway { Creates a new Edge Gateway with Default Parameters Default Parameters are: - * Size * HA State * DNS Relay @@ -17,14 +14,14 @@ Function New-MyEdgeGateway { .NOTES File Name : New-MyEdgeGateway.ps1 Author : Markus Kraus - Version : 1.0 + Version : 1.1 State : Ready .LINK https://mycloudrevolution.com/ .EXAMPLE - New-MyEdgeGateway -Name "TestEdge" -OrgVDCName "TestVDC" -OrgName "TestOrg" -ExternalNetwork "ExternalNetwork" -IPAddress "192.168.100.1" -SubnetMask "255.255.255.0" -Gateway "192.168.100.254" -IPRangeStart ""192.168.100.2" -IPRangeEnd ""192.168.100.3" -Verbose + New-MyEdgeGateway -Name "TestEdge" -OrgVDCName "TestVDC" -OrgName "TestOrg" -Size compact -ExternalNetwork "ExternalNetwork" -IPAddress "192.168.100.1" -SubnetMask "255.255.255.0" -Gateway "192.168.100.254" -IPRangeStart ""192.168.100.2" -IPRangeEnd ""192.168.100.3" -Verbose .PARAMETER Name Name of the New Edge Gateway as String @@ -35,6 +32,9 @@ Function New-MyEdgeGateway { .PARAMETER OrgName Org where the new Edge Gateway should be created as string +.PARAMETER Size + Size of the new Edge Gateway as string + .PARAMETER ExternalNetwork External Network of the new Edge Gateway as String @@ -69,6 +69,10 @@ Function New-MyEdgeGateway { [Parameter(Mandatory=$True, ValueFromPipeline=$False, HelpMessage="Org where the new Edge Gateway should be created as string")] [ValidateNotNullorEmpty()] [String] $OrgName, + [Parameter(Mandatory=$True, ValueFromPipeline=$False, HelpMessage="Size of the new Edge Gateway as string")] + [ValidateNotNullorEmpty()] + [ValidateSet("compact","full")] + [String] $Size, [Parameter(Mandatory=$True, ValueFromPipeline=$False, HelpMessage="External Network of the New Edge Gateway as String")] [ValidateNotNullorEmpty()] [String] $ExternalNetwork, @@ -113,7 +117,7 @@ Function New-MyEdgeGateway { $EdgeGateway.Name = $Name $EdgeGateway.Configuration = New-Object VMware.VimAutomation.Cloud.Views.GatewayConfiguration #$EdgeGateway.Configuration.BackwardCompatibilityMode = $false - $EdgeGateway.Configuration.GatewayBackingConfig = "compact" + $EdgeGateway.Configuration.GatewayBackingConfig = $Size $EdgeGateway.Configuration.UseDefaultRouteForDnsRelay = $false $EdgeGateway.Configuration.HaEnabled = $false diff --git a/Modules/VMware-vCD-Module/functions/New-MyOrg.psm1 b/Modules/VMware-vCD-Module/functions/New-MyOrg.psm1 index 69565bb..6d995e4 100644 --- a/Modules/VMware-vCD-Module/functions/New-MyOrg.psm1 +++ b/Modules/VMware-vCD-Module/functions/New-MyOrg.psm1 @@ -1,6 +1,4 @@ -#Requires -Version 4 -#Requires -Modules VMware.VimAutomation.Cloud, @{ModuleName="VMware.VimAutomation.Cloud";ModuleVersion="6.3.0.0"} -Function New-MyOrg { +Function New-MyOrg { <# .SYNOPSIS Creates a new vCD Org with Default Parameters diff --git a/Modules/VMware-vCD-Module/functions/New-MyOrgAdmin.psm1 b/Modules/VMware-vCD-Module/functions/New-MyOrgAdmin.psm1 index 26087c0..227d30e 100644 --- a/Modules/VMware-vCD-Module/functions/New-MyOrgAdmin.psm1 +++ b/Modules/VMware-vCD-Module/functions/New-MyOrgAdmin.psm1 @@ -1,6 +1,4 @@ -#Requires -Version 4 -#Requires -Modules VMware.VimAutomation.Cloud, @{ModuleName="VMware.VimAutomation.Cloud";ModuleVersion="6.3.0.0"} -Function New-MyOrgAdmin { +Function New-MyOrgAdmin { <# .SYNOPSIS Creates a new vCD Org Admin with Default Parameters diff --git a/Modules/VMware-vCD-Module/functions/New-MyOrgNetwork.psm1 b/Modules/VMware-vCD-Module/functions/New-MyOrgNetwork.psm1 new file mode 100644 index 0000000..2d7bf5a --- /dev/null +++ b/Modules/VMware-vCD-Module/functions/New-MyOrgNetwork.psm1 @@ -0,0 +1,166 @@ +Function New-MyOrgNetwork { + <# + .SYNOPSIS + Creates a new Org Network with Default Parameters + + .DESCRIPTION + + .NOTES + File Name : New-MyOrgNetwork.ps1 + Author : Markus Kraus + Version : 1.1 + State : Ready + + .LINK + https://mycloudrevolution.com + + .EXAMPLE + New-MyOrgNetwork -Name Test -OrgVdcName "Test-OrgVDC" -OrgName "Test-Org" -EdgeName "Test-OrgEdge" -SubnetMask 255.255.255.0 -Gateway 192.168.66.1 -IPRangeStart 192.168.66.100 -IPRangeEnd 192.168.66.200 + + .EXAMPLE + New-MyOrgNetwork -Name Test -OrgVdcName "Test-OrgVDC" -OrgName "Test-Org" -EdgeName "Test-OrgEdge" -SubnetMask 255.255.255.0 -Gateway 192.168.66.1 -IPRangeStart 192.168.66.100 -IPRangeEnd 192.168.66.200 -Shared:$False + + .EXAMPLE + $params = @{ 'Name' = 'Test'; + 'OrgVdcName'= 'Test-OrgVDC'; + 'OrgName'='Test-Org'; + 'EdgeName'='Test-OrgEdge'; + 'SubnetMask' = '255.255.255.0'; + 'Gateway' = '192.168.66.1'; + 'IPRangeStart' = '192.168.66.100'; + 'IPRangeEnd' = '192.168.66.200' + } + New-MyOrgNetwork @params -Verbose + + .PARAMETER Name + Name of the New Org Network as String + + .PARAMETER OrgVDCName + OrgVDC where the new Org Network should be created as string + + .PARAMETER OrgName + Org where the newOrg Networkshould be created as string + + .PARAMETER EdgeName + Edge Gateway Name for the new Org Network as String + + .PARAMETER SubnetMask + Subnet Mask of the New Org Network as IP Address + + .PARAMETER Gateway + Gateway of the New Org Network as IP Address + + .PARAMETER IPRangeStart + IP Range Start of the New Org Network as IP Address + + .PARAMETER IPRangeEnd + IP Range End of the New Org Network as IP Address + + .PARAMETER Shared + Switch for Shared OrgVDC Network + + Default: $True + + .PARAMETER Timeout + Timeout for the Org Network to become Ready + + Default: 120s + + #> + Param ( + [Parameter(Mandatory=$True, ValueFromPipeline=$False, HelpMessage="Name of the New Org Network as String")] + [ValidateNotNullorEmpty()] + [String] $Name, + [Parameter(Mandatory=$True, ValueFromPipeline=$False, HelpMessage="OrgVDC where the new Org Network should be created as string")] + [ValidateNotNullorEmpty()] + [String] $OrgVdcName, + [Parameter(Mandatory=$True, ValueFromPipeline=$False, HelpMessage="Org where the new Org Network should be created as string")] + [ValidateNotNullorEmpty()] + [String] $OrgName, + [Parameter(Mandatory=$True, ValueFromPipeline=$False, HelpMessage="Edge Gateway Name for the new Org Network as String")] + [ValidateNotNullorEmpty()] + [String] $EdgeName, + [Parameter(Mandatory=$True, ValueFromPipeline=$False, HelpMessage="Subnet Mask of the New Org Network as IP Address")] + [ValidateNotNullorEmpty()] + [IPAddress] $SubnetMask, + [Parameter(Mandatory=$True, ValueFromPipeline=$False, HelpMessage="Gateway of the New Org Network as IP Address")] + [ValidateNotNullorEmpty()] + [IPAddress] $Gateway, + [Parameter(Mandatory=$True, ValueFromPipeline=$False, HelpMessage="IP Range Start the New Org Network as IP Address")] + [ValidateNotNullorEmpty()] + [IPAddress] $IPRangeStart, + [Parameter(Mandatory=$True, ValueFromPipeline=$False, HelpMessage="IP Range End the New Org Network as IP Address")] + [ValidateNotNullorEmpty()] + [IPAddress] $IPRangeEnd, + [Parameter(Mandatory=$False, ValueFromPipeline=$False, HelpMessage="Switch for Shared OrgVDC Network")] + [ValidateNotNullorEmpty()] + [Bool] $Shared = $True, + [Parameter(Mandatory=$False, ValueFromPipeline=$False,HelpMessage="Timeout for the Org Network to become Ready")] + [ValidateNotNullorEmpty()] + [int] $Timeout = 120 + ) + Process { + + ## Get Org vDC + Write-Verbose "Get Org vDC" + [Array] $orgVdc = Get-Org -Name $OrgName | Get-OrgVdc -Name $OrgVdcName + + if ( $orgVdc.Count -gt 1) { + throw "Multiple OrgVdcs found!" + } + elseif ( $orgVdc.Count -lt 1) { + throw "No OrgVdc found!" + } + $orgVdcView = $orgVdc| Get-CIView + + ## Get EdgeGateway + Write-Verbose "Get EdgeGateway" + [Array] $edgeGateway = Search-Cloud -QueryType EdgeGateway -Name $EdgeName | Get-CIView + if ( $edgeGateway.Count -gt 1) { + throw "Multiple EdgeGateways found!" + } + elseif ( $edgeGateway.Count -lt 1) { + throw "No EdgeGateway found!" + } + + ## Define Org Network + Write-Verbose "Define Org Network" + $OrgNetwork = new-object vmware.vimautomation.cloud.views.orgvdcnetwork + $OrgNetwork.name = $Name + $OrgNetwork.edgegateway = $edgeGateway.id + $OrgNetwork.isshared = $Shared + + $OrgNetwork.configuration = new-object vmware.vimautomation.cloud.views.networkconfiguration + $OrgNetwork.configuration.fencemode = "natRouted" + $OrgNetwork.configuration.ipscopes = new-object vmware.vimautomation.cloud.views.ipscopes + + $Scope = new-object vmware.vimautomation.cloud.views.ipScope + $Scope.gateway = $Gateway + $Scope.netmask = $SubnetMask + + $Scope.ipranges = new-object vmware.vimautomation.cloud.views.ipranges + $Scope.ipranges.iprange = new-object vmware.vimautomation.cloud.views.iprange + $Scope.ipranges.iprange[0].startaddress = $IPRangeStart + $Scope.ipranges.iprange[0].endaddress = $IPRangeEnd + + $OrgNetwork.configuration.ipscopes.ipscope += $Scope + + ## Create Org Network + Write-Verbose "Create Org Network" + $CreateOrgNetwork = $orgVdcView.CreateNetwork($OrgNetwork) + + ## Wait for Org Network to become Ready + Write-Verbose "Wait for Org Network to become Ready" + while(!(Get-OrgVdcNetwork -Id $CreateOrgNetwork.Id -ErrorAction SilentlyContinue)){ + $i++ + Start-Sleep 5 + if($i -gt $Timeout) { Write-Error "Creating Org Network."; break} + Write-Progress -Activity "Creating Org Network" -Status "Wait for Network to become Ready..." + } + Write-Progress -Activity "Creating Org Network" -Completed + Start-Sleep 1 + + Get-OrgVdcNetwork -Id $CreateOrgNetwork.Id | Select-Object Name, OrgVdc, NetworkType, DefaultGateway, Netmask, StaticIPPool, @{ N='isShared'; E = {$_.ExtensionData.isShared} } | Format-Table -AutoSize + + } + } diff --git a/Modules/VMware-vCD-Module/functions/New-MyOrgVdc.psm1 b/Modules/VMware-vCD-Module/functions/New-MyOrgVdc.psm1 index 26258e7..90e4cd0 100644 --- a/Modules/VMware-vCD-Module/functions/New-MyOrgVdc.psm1 +++ b/Modules/VMware-vCD-Module/functions/New-MyOrgVdc.psm1 @@ -1,6 +1,4 @@ -#Requires -Version 4 -#Requires -Modules VMware.VimAutomation.Cloud, @{ModuleName="VMware.VimAutomation.Cloud";ModuleVersion="6.3.0.0"} -Function New-MyOrgVdc { +Function New-MyOrgVdc { <# .SYNOPSIS Creates a new vCD Org VDC with Default Parameters @@ -9,7 +7,6 @@ Function New-MyOrgVdc { Creates a new vCD Org VDC with Default Parameters Default Parameters are: - * Allocation Model * Network Quota * VM Quota * 'vCpu In Mhz' @@ -20,27 +17,38 @@ Function New-MyOrgVdc { .NOTES File Name : New-MyOrgVdc.ps1 Author : Markus Kraus - Version : 1.2 + Version : 1.3 State : Ready .LINK https://mycloudrevolution.com/ .EXAMPLE - New-MyOrgVdc -Name "TestVdc" -CPULimit 1000 -MEMLimit 1000 -StorageLimit 1000 -StorageProfile "Standard-DC01" -NetworkPool "NetworkPool-DC01" -ProviderVDC "Provider-VDC-DC01" -Org "TestOrg" -ExternalNetwork "External_OrgVdcNet" + New-MyOrgVdc -Name "TestVdc" -AllocationModel AllocationPool -CPULimit 1000 -MEMLimit 1000 -StorageLimit 1000 -StorageProfile "Standard-DC01" -NetworkPool "NetworkPool-DC01" -ProviderVDC "Provider-VDC-DC01" -Org "TestOrg" -ExternalNetwork "External_OrgVdcNet" .EXAMPLE - New-MyOrgVdc -Name "TestVdc" -CPULimit 1000 -MEMLimit 1000 -StorageLimit 1000 -StorageProfile "Standard-DC01" -NetworkPool "NetworkPool-DC01" -ProviderVDC "Provider-VDC-DC01" -Org "TestOrg" + New-MyOrgVdc -Name "TestVdc" -AllocationModel AllocationVApp -StorageLimit 1000 -StorageProfile "Standard-DC01" -NetworkPool "NetworkPool-DC01" -ProviderVDC "Provider-VDC-DC01" -Org "TestOrg" .PARAMETER Name Name of the New Org VDC as String +.PARAMETER AllocationModel + Allocation Model of the New Org VDC as String + .PARAMETER CPULimit CPU Limit (MHz) of the New Org VDC as String + Default: 0 (Unlimited) + + Note: If AllocationModel is not AllocationVApp (Pay as you go), a limit needs to be set + .PARAMETER MEMLimit Memory Limit (MB) of the New Org VDC as String + Default: 0 (Unlimited) + + Note: If AllocationModel is not AllocationVApp (Pay as you go), a limit needs to be set + .PARAMETER StorageLimit Storage Limit (MB) of the New Org VDC as String @@ -76,12 +84,16 @@ Function New-MyOrgVdc { [Parameter(Mandatory=$True, ValueFromPipeline=$False, HelpMessage="Name of the New Org VDC as String")] [ValidateNotNullorEmpty()] [String] $Name, - [Parameter(Mandatory=$True, ValueFromPipeline=$False, HelpMessage="CPU Limit (MHz) of the New Org VDC as String")] + [Parameter(Mandatory=$True, ValueFromPipeline=$False, HelpMessage="Allocation Model of the New Org VDC as String")] [ValidateNotNullorEmpty()] - [int] $CPULimit, - [Parameter(Mandatory=$True, ValueFromPipeline=$False, HelpMessage="Memory Limit (MB) of the New Org VDC as String")] + [ValidateSet("AllocationPool","AllocationVApp")] + [String] $AllocationModel, + [Parameter(Mandatory=$False, ValueFromPipeline=$False, HelpMessage="CPU Limit (MHz) of the New Org VDC as String")] [ValidateNotNullorEmpty()] - [int] $MEMLimit, + [int] $CPULimit = 0, + [Parameter(Mandatory=$False, ValueFromPipeline=$False, HelpMessage="Memory Limit (MB) of the New Org VDC as String")] + [ValidateNotNullorEmpty()] + [int] $MEMLimit = 0, [Parameter(Mandatory=$True, ValueFromPipeline=$False, HelpMessage="Storage Limit (MB) of the New Org VDC as String")] [ValidateNotNullorEmpty()] [int] $StorageLimit, @@ -117,7 +129,7 @@ Function New-MyOrgVdc { $providerVdcRef = New-Object VMware.VimAutomation.Cloud.Views.Reference $providerVdcRef.Href = $OrgVdcproviderVdc.Href $adminVdc.ProviderVdcReference = $providerVdcRef - $adminVdc.AllocationModel = "AllocationPool" + $adminVdc.AllocationModel = $AllocationModel $adminVdc.ComputeCapacity = New-Object VMware.VimAutomation.Cloud.Views.ComputeCapacity $adminVdc.ComputeCapacity.Cpu = New-Object VMware.VimAutomation.Cloud.Views.CapacityWithUsage $adminVdc.ComputeCapacity.Cpu.Units = "MHz" @@ -132,8 +144,8 @@ Function New-MyOrgVdc { $adminVdc.StorageCapacity.Limit = $StorageLimit $adminVdc.NetworkQuota = 10 $adminVdc.VmQuota = 0 - $adminVdc.VCpuInMhz = 1000 - $adminVdc.VCpuInMhz2 = 1000 + $adminVdc.VCpuInMhz = 2000 + $adminVdc.VCpuInMhz2 = 2000 $adminVdc.UsesFastProvisioning = $false $adminVdc.IsThinProvision = $true @@ -143,20 +155,21 @@ Function New-MyOrgVdc { $orgVdc = $orgED.CreateVdc($adminVdc) ## Wait for getting Ready - Write-Verbose "Wait for getting Ready" + Write-Verbose "Wait for OrgVdc getting Ready after creation" $i = 0 while(($orgVdc = Get-OrgVdc -Name $Name -Verbose:$false).Status -eq "NotReady"){ $i++ Start-Sleep 2 - if($i -gt $Timeout) { Write-Error "Creating Org Failed."; break} - Write-Progress -Activity "Creating Org" -Status "Wait for Org to become Ready..." + if($i -gt $Timeout) { Write-Error "Creating OrgVdc Failed."; break} + Write-Progress -Activity "Creating OrgVdc" -Status "Wait for OrgVdc to become Ready..." } - Write-Progress -Activity "Creating Org" -Completed + Write-Progress -Activity "Creating OrgVdc" -Completed Start-Sleep 2 ## Search given Storage Profile Write-Verbose "Search given Storage Profile" - $ProVdcStorageProfile = search-cloud -QueryType ProviderVdcStorageProfile -Name $StorageProfile | Get-CIView + $Filter = "ProviderVdc==" + $OrgVdcproviderVdc.Id + $ProVdcStorageProfile = search-cloud -QueryType ProviderVdcStorageProfile -Name $StorageProfile -Filter $Filter | Get-CIView ## Create Storage Profile Object with Settings Write-Verbose "Create Storage Profile Object with Settings" @@ -174,14 +187,14 @@ Function New-MyOrgVdc { $orgVdc.ExtensionData.CreateVdcStorageProfile($UpdateParams) ## Wait for getting Ready - Write-Verbose "Wait for getting Ready" + Write-Verbose "Wait for OrgVdc getting Ready after update" while(($orgVdc = Get-OrgVdc -Name $name -Verbose:$false).Status -eq "NotReady"){ $i++ Start-Sleep 1 - if($i -gt $Timeout) { Write-Error "Update Org Failed."; break} - Write-Progress -Activity "Updating Org" -Status "Wait for Org to become Ready..." + if($i -gt $Timeout) { Write-Error "Update OrgVdc Failed."; break} + Write-Progress -Activity "Updating OrgVdc" -Status "Wait for OrgVdc to become Ready..." } - Write-Progress -Activity "Updating Org" -Completed + Write-Progress -Activity "Updating OrgVdc" -Completed Start-Sleep 1 ## Search Any-StorageProfile From d4f4e64ca33179631e681e80cf5ee5d4dd05127d Mon Sep 17 00:00:00 2001 From: simonfangyingzhang Date: Fri, 27 Apr 2018 04:18:51 +0100 Subject: [PATCH 07/22] Deprecating functions related to KMServer and KMSCluster from VMware.VMEncryption --- Modules/VMware.VMEncryption/README.md | 29 +++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/Modules/VMware.VMEncryption/README.md b/Modules/VMware.VMEncryption/README.md index 9e38900..d01c5fa 100644 --- a/Modules/VMware.VMEncryption/README.md +++ b/Modules/VMware.VMEncryption/README.md @@ -2,6 +2,31 @@ Prerequisites/Steps to use this module: 1. This module only works for vSphere products that support VM Encryption. E.g. vSphere 6.5 and later. 2. All the functions in this module only work for KMIP Servers. -3. Install the latest version of Powershell and PowerCLI(6.5). +3. Install the latest version of Powershell and PowerCLI. 4. Import this module by running: Import-Module -Name "location of this module" -5. Get-Command -Module "This module Name" to list all available functions. \ No newline at end of file +5. Get-Command -Module "This module Name" to list all available functions. + +Note: +Deprecating the below functions related to KMServer and KMSCluster from VMware.VMEncryption and using instead the ones from VMware.VimAutomation.Storage, + +1, VMware.VMEncryption\Get-DefaultKMSCluster, use instead +VMware.VimAutomation.Storage\Get-KmsCluster|where {$_.UseAsDefaultKeyProvider}|foreach {$_.id} + +2, VMware.VMEncryption\Get-KMSCluster, use instead +VMware.VimAutomation.Storage\Get-KmsCluster|select id + +3, VMware.VMEncryption\Get-KMSClusterInfo, use instead +VMware.VimAutomation.Storage\Get-KmsCluster|foreach {$_.extensiondata} + +4, VMware.VMEncryption\Get-KMServerInfo, use instead +VMware.VimAutomation.Storage\Get-KeyManagementServer|foreach {$_.extensiondata} + +5, VMware.VMEncryption\New-KMServer, use instead +VMware.VimAutomation.Storage\Add-KeyManagementServer + +6, VMware.VMEncryption\Remove-KMServer, use instead +VMware.VimAutomation.Storage\Remove-KeyManagementServer + +7, VMware.VMEncryption\Set-DefaultKMSCluster, use instead +VMware.VimAutomation.Storage\Set-KmsCluster -UseAsDefaultKeyProvider + From d70bee9f99ce1475578cf8e5bd6f16dbb15edc0d Mon Sep 17 00:00:00 2001 From: simonfangyingzhang Date: Fri, 27 Apr 2018 04:19:53 +0100 Subject: [PATCH 08/22] Update VMware.VMEncryption.psd1 --- .../VMware.VMEncryption.psd1 | Bin 5090 -> 2621 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/Modules/VMware.VMEncryption/VMware.VMEncryption.psd1 b/Modules/VMware.VMEncryption/VMware.VMEncryption.psd1 index d3106326576f014d290d1010af53ab6bbfbeac3c..45b17c105a656c9254698dda7cf3c548d6587fc1 100644 GIT binary patch literal 2621 zcmbtW+iu%95PjEI4D1IdMXXq<*NwXU>01r3C09+E2Rl}e}G=k;@+dulpct>oS_1l2QPP%IP%tw5jiDs;{2xPP;0t} zkx&c%qsC$lJVRl4zTSk0K7Auoa?Hnnj8AZQ+8?Fa+x~Do#Qy0xne`Eq0pd7+H%Lw$ z@}xEky5DvtQTR$go;7EBCd-P6HIVrdMfTJy7+kXwZ4Tb`2&N*913Hsa9)c}VsG_44tu$D{ z%^E5tmqegd#uk5F*mR{7T;f+;@UkxH+P-`N@^4NotTf!n6{@cbq-;>kxj@S1N6po9 z@Q=0|Wp+UvZ7(A)B+34Fa6gk_Q-W7!|Ed_f`M*F?e0^~Tmx?s8lIr`O8=OmXji$By zP54xnB^9|~VqUX3F<(mOiir_=~@arf`3j& zM=&X~(QqGZi!s@RXm#W?u1Rr>hD%KaogwhDlFAM#E~vfD0%2ar8M9hiawUaplS*;Q zi_X0@7xOLI-Uhw-0ivn-hgx4V@32W=`^w+FO>)c0+t76?Xm%hJg{XO$Koi z58~6e!_jy+>imoj?f9B#jpeN1xO0U?I~gkEC~|@C))h^M$FL7&L6M~`O}N);ffU}AX_xpe zSoh~(FQp=i{|B%Kcn-R$aw`YgMIdM`QVq%=u`o#dU(gk%Jm*ei8++;4BekSN*AAq? zx3zh0yHat=r02-H3{#Z^Apsw(k|9^J+)`(2bSE#o2{pu<{u{p(%B(=M*Z<6$YS;6dy-WomipA?+w{ocXksqYs~?Mp0^99z;WmVT!pl)=V>AguQ03FF*a(Qkry z3BCwH8onfvZu{RTzNAeG88ggsP|>5r{@N+>%F=fsfSp^cW@3HDqMC|a!nfP$?jxZK z&8a7~??WV2)`(B*T Vzj64swL?UDeb^}edr0SJ^dD9YJ~-Z*?vM42L@cA*ZYR~<-us>jcqmMy$9yVPKfYfz_H@#rUb8p#*X z@i)Vcyag*$BvnxNu`jmw8&H(hN{07J?Q;!Y)HA_%4Aga9O|aIQk>&NFoRIe{CzG@Z zUp))toyY+=j)C0#F@g*}GX}ol+JyeJO9pSzd-Q8dS3-?FijusOk78U+VhcWcf$tXR zw`E5*;Hebcp5tyC>)Tl0!1^wHSjSxxpG{!obr-T;sdsk*%zMB^>E^%NY*LbVuOSL! zjqz!g-v_@g;)L-}jg9+vpy&Z@5m_;Zb8zZ{I+488Cs;iJ-xS`65ey)E2phMdAG41+ zXz@l~w7<{DMIIoISw4ng-kWuxcm%F4i{e}iktVQa2cINB$cSeJVEhb))@npL9q2n& z1a?SzUarLv?_k5kJPY4f%|D_7CQ=)xUMwms6=~m02dfjQTDeE+CivnYDtR%je69_epXYfORS=_Qcpc&-Gud(^^W#3`j9udw)Ksl zZ#+ipoK;8*Yg{;mPz!4L78ZYW(`)zCM@^up16v0A+qI=0HTcD5l+`1ik0*~io+jON zNbKwAdIM;&sd3}|X7jPj3Hpswo%2wtzTt#9#2i3A>>jK3lAAz7^w+39eRQxeXXbh8 z5`XT#K$cY*qMqI2C zKaQqxb^_++NNvBI?0q2fT#CrOg0ESTYg!v!Wn^yMSMNNhBJw%oQ#vR5!MF3TQ&8aalB9eC;l zdB^{c68tAn#gp^xqD-ZXSz1RqD}!ge77*~CD@F~c09=^4%;R&99Y(_$Q)+T09vf>?Gl+eTDj6a4Q%+dBL%Vq+b7dgt72x`g}P Me+=e<-#Tag10n%j>;M1& From df9d71d4e0b80a7d4617cc81020cd88dc79a6e2e Mon Sep 17 00:00:00 2001 From: simonfangyingzhang Date: Fri, 27 Apr 2018 04:22:42 +0100 Subject: [PATCH 09/22] Update VMware.VMEncryption.psm1 1, added new function Set-VMCryptoUnlock 2, deprecating functions related to KMServer and KMSCluster from VMware.VMEncryption --- .../VMware.VMEncryption.psm1 | 216 ++++++------------ 1 file changed, 68 insertions(+), 148 deletions(-) diff --git a/Modules/VMware.VMEncryption/VMware.VMEncryption.psm1 b/Modules/VMware.VMEncryption/VMware.VMEncryption.psm1 index 023087c..4085365 100644 --- a/Modules/VMware.VMEncryption/VMware.VMEncryption.psm1 +++ b/Modules/VMware.VMEncryption/VMware.VMEncryption.psm1 @@ -1,5 +1,5 @@ # Script Module : VMware.VMEncryption -# Version : 1.0 +# Version : 1.1 # Copyright © 2016 VMware, Inc. All Rights Reserved. @@ -56,8 +56,13 @@ New-VIProperty -Name EncryptionKeyId -ObjectType VirtualMachine -Value { New-VIProperty -Name Locked -ObjectType VirtualMachine -Value { Param ($VM) - ($vm.extensiondata.Runtime.ConnectionState -eq "invalid") -and ($vm.extensiondata.Config.KeyId) -} -BasedOnExtensionProperty 'Runtime.ConnectionState','Config.KeyId' -Force | Out-Null + if ($vm.ExtensionData.Runtime.CryptoState) { + $vm.ExtensionData.Runtime.CryptoState -eq "locked" + } + else { + ($vm.extensiondata.Runtime.ConnectionState -eq "invalid") -and ($vm.extensiondata.Config.KeyId) + } +} -BasedOnExtensionProperty 'Runtime.CryptoState', 'Runtime.ConnectionState','Config.KeyId' -Force | Out-Null New-VIProperty -Name vMotionEncryption -ObjectType VirtualMachine -Value { Param ($VM) @@ -83,13 +88,6 @@ New-VIProperty -Name EncryptionKeyId -ObjectType HardDisk -Value { } } -BasedOnExtensionProperty 'Backing.KeyId' -Force | Out-Null -New-VIProperty -Name KMSserver -ObjectType VMHost -Value { - Param ($VMHost) - if ($VMHost.CryptoSafe) { - $VMHost.ExtensionData.Runtime.CryptoKeyId.ProviderId.Id - } -} -BasedOnExtensionProperty 'Runtime.CryptoKeyId.ProviderId.Id' -Force | Out-Null - Function Enable-VMHostCryptoSafe { <# .SYNOPSIS @@ -113,13 +111,6 @@ Function Enable-VMHostCryptoSafe { .NOTES Author : Baoyin Qiao. Author email : bqiao@vmware.com - Version : 1.0 - - ==========Tested Against Environment========== - VMware vSphere Hypervisor(ESXi) Version : 6.5 - VMware vCenter Server Version : 6.5 - PowerCLI Version : PowerCLI 6.5 - PowerShell Version : 3.0 #> [CmdLetBinding()] @@ -181,13 +172,6 @@ Function Set-VMHostCryptoKey { .NOTES Author : Baoyin Qiao. Author email : bqiao@vmware.com - Version : 1.0 - - ==========Tested Against Environment========== - VMware vSphere Hypervisor(ESXi) Version : 6.5 - VMware vCenter Server Version : 6.5 - PowerCLI Version : PowerCLI 6.5 - PowerShell Version : 3.0 #> [CmdLetBinding()] @@ -266,13 +250,6 @@ Function Set-vMotionEncryptionConfig { .NOTES Author : Brian Graf, Carrie Yang. Author email : grafb@vmware.com, yangm@vmware.com - Version : 1.0 - - ==========Tested Against Environment========== - VMware vSphere Hypervisor(ESXi) Version : 6.5 - VMware vCenter Server Version : 6.5 - PowerCLI Version : PowerCLI 6.5 - PowerShell Version : 3.0 #> [CmdLetBinding()] @@ -348,13 +325,6 @@ Function Enable-VMEncryption { .NOTES Author : Baoyin Qiao. Author email : bqiao@vmware.com - Version : 1.0 - - ==========Tested Against Environment========== - VMware vSphere Hypervisor(ESXi) Version : 6.5 - VMware vCenter Server Version : 6.5 - PowerCLI Version : PowerCLI 6.5 - PowerShell Version : 3.0 #> [CmdLetBinding()] @@ -508,13 +478,6 @@ Function Enable-VMDiskEncryption { .NOTES Author : Baoyin Qiao. Author email : bqiao@vmware.com - Version : 1.0 - - ==========Tested Against Environment========== - VMware vSphere Hypervisor(ESXi) Version : 6.5 - VMware vCenter Server Version : 6.5 - PowerCLI Version : PowerCLI 6.5 - PowerShell Version : 3.0 #> [CmdLetBinding()] @@ -660,13 +623,6 @@ Function Disable-VMEncryption { .NOTES Author : Carrie Yang. Author email : yangm@vmware.com - Version : 1.0 - - ==========Tested Against Environment========== - VMware vSphere Hypervisor(ESXi) Version : 6.5 - VMware vCenter Server Version : 6.5 - PowerCLI Version : PowerCLI 6.5 - PowerShell Version : 3.0 #> [CmdLetBinding()] @@ -756,13 +712,6 @@ Function Disable-VMDiskEncryption { .NOTES Author : Carrie Yang. Author email : yangm@vmware.com - Version : 1.0 - - ==========Tested Against Environment========== - VMware vSphere Hypervisor(ESXi) Version : 6.5 - VMware vCenter Server Version : 6.5 - PowerCLI Version : PowerCLI 6.5 - PowerShell Version : 3.0 #> [CmdLetBinding()] @@ -882,7 +831,7 @@ Function Set-VMEncryptionKey { C:\PS>$VM|Set-VMEncryptionKey -KMSClusterId $KMSCluster.Id -Deep Deep rekeys the VM Home and all its disks using a new key. - The key is generated from the KMS whose clusterId is $KMSCluster.Id. + The key is generted from the KMS whose clusterId is $KMSCluster.Id. .NOTES This cmdlet assumes there is already a KMS in vCenter Server. If VM is not encrypted, the cmdlet quits. @@ -891,13 +840,6 @@ Function Set-VMEncryptionKey { .NOTES Author : Carrie Yang. Author email : yangm@vmware.com - Version : 1.0 - - ==========Tested Against Environment========== - VMware vSphere Hypervisor(ESXi) Version : 6.5 - VMware vCenter Server Version : 6.5 - PowerCLI Version : PowerCLI 6.5 - PowerShell Version : 3.0 #> [CmdLetBinding()] @@ -1034,10 +976,10 @@ Function Set-VMDiskEncryptionKey { C:\PS>$KMSCluster = Get-KMSCluster | select -last 1 C:\PS>$VM = Get-VM -Name win2012 C:\PS>$HardDisk = get-vm $vm|Get-HardDisk - C:\PS>$HardDisk| Set-VMDiskEncryptionKey -VM $VM -KMSClusterId $KMSCluster.Id -Deep + C:\PS>$HardDisk|$Set-VMEncryptionKey -VM $VM -KMSClusterId $KMSCluster.Id -Deep Deep rekeys all the disks of the $VM using a new key. - The key is generated from the KMS whose clusterId is $KMSCluster.Id. + The key is generted from the KMS whose clusterId is $KMSCluster.Id. .NOTES This cmdlet assumes there is already a KMS in vCenter Server. @@ -1047,13 +989,6 @@ Function Set-VMDiskEncryptionKey { .NOTES Author : Carrie Yang. Author email : yangm@vmware.com - Version : 1.0 - - ==========Tested Against Environment========== - VMware vSphere Hypervisor(ESXi) Version : 6.5 - VMware vCenter Server Version : 6.5 - PowerCLI Version : PowerCLI 6.5 - PowerShell Version : 3.0 #> [CmdLetBinding()] @@ -1170,13 +1105,6 @@ Function Get-VMEncryptionInfo { .NOTES Author : Carrie Yang. Author email : yangm@vmware.com - Version : 1.0 - - ==========Tested Against Environment========== - VMware vSphere Hypervisor(ESXi) Version : 6.5 - VMware vCenter Server Version : 6.5 - PowerCLI Version : PowerCLI 6.5 - PowerShell Version : 3.0 #> [CmdLetBinding()] @@ -1269,13 +1197,6 @@ Function Get-EntityByCryptoKey { .NOTES Author : Baoyin Qiao. Author email : bqiao@vmware.com - Version : 1.0 - - ==========Tested Against Environment========== - VMware vSphere Hypervisor(ESXi) Version : 6.5 - VMware vCenter Server Version : 6.5 - PowerCLI Version : PowerCLI 6.5 - PowerShell Version : 3.0 #> [CmdLetBinding()] @@ -1394,13 +1315,6 @@ Function New-KMServer { .NOTES Author : Baoyin Qiao. Author email : bqiao@vmware.com - Version : 1.0 - - ==========Tested Against Environment========== - VMware vSphere Hypervisor(ESXi) Version : 6.5 - VMware vCenter Server Version : 6.5 - PowerCLI Version : PowerCLI 6.5 - PowerShell Version : 3.0 #> [CmdLetBinding()] @@ -1435,6 +1349,7 @@ Function New-KMServer { ) Begin { + write-warning "This cmdlet is deprecated and will be removed in future release. Use VMware.VimAutomation.Storage\Add-KeyManagementServer instead" # Confirm the connected VIServer is vCenter Server ConfirmIsVCenter @@ -1553,13 +1468,6 @@ Function Remove-KMServer { .NOTES Author : Baoyin Qiao. Author email : bqiao@vmware.com - Version : 1.0 - - ==========Tested Against Environment========== - VMware vSphere Hypervisor(ESXi) Version : 6.5 - VMware vCenter Server Version : 6.5 - PowerCLI Version : PowerCLI 6.5 - PowerShell Version : 3.0 #> [CmdLetBinding()] @@ -1573,6 +1481,7 @@ Function Remove-KMServer { ) Begin { + write-warning "This cmdlet is deprecated and will be removed in future release. Use VMware.VimAutomation.Storage\Remove-KeyManagementServer instead" # Confirm the connected VIServer is vCenter Server ConfirmIsVCenter @@ -1630,15 +1539,9 @@ Function Get-KMSCluster { .NOTES Author : Baoyin Qiao. Author email : bqiao@vmware.com - Version : 1.0 - - ==========Tested Against Environment========== - VMware vSphere Hypervisor(ESXi) Version : 6.5 - VMware vCenter Server Version : 6.5 - PowerCLI Version : PowerCLI 6.5 - PowerShell Version : 3.0 #> + write-warning "This cmdlet is deprecated and will be removed in future release. Use VMware.VimAutomation.Storage\Get-KmsCluster instead" # Confirm the connected VIServer is vCenter Server ConfirmIsVCenter @@ -1668,14 +1571,6 @@ Function Get-KMSClusterInfo { .NOTES Author : Baoyin Qiao. Author email : bqiao@vmware.com - Version : 1.0 - - ==========Tested Against Environment========== - VMware vSphere Hypervisor(ESXi) Version : 6.5 - VMware vCenter Server Version : 6.5 - PowerCLI Version : PowerCLI 6.5 - PowerShell Version : 3.0 - #> [CmdLetBinding()] @@ -1686,6 +1581,7 @@ Function Get-KMSClusterInfo { ) Begin { + write-warning "This cmdlet is deprecated and will be removed in future release. Use VMware.VimAutomation.Storage\Get-KmsCluster instead" # Confirm the connected VIServer is vCenter Server ConfirmIsVCenter @@ -1721,13 +1617,6 @@ Function Get-KMServerInfo { .NOTES Author : Baoyin Qiao. Author email : bqiao@vmware.com - Version : 1.0 - - ==========Tested Against Environment========== - VMware vSphere Hypervisor(ESXi) Version : 6.5 - VMware vCenter Server Version : 6.5 - PowerCLI Version : PowerCLI 6.5 - PowerShell Version : 3.0 #> [CmdLetBinding()] @@ -1738,6 +1627,7 @@ Function Get-KMServerInfo { ) Begin { + write-warning "This cmdlet is deprecated and will be removed in future release. Use VMware.VimAutomation.Storage\Get-KeyManagementServer instead" # Confirm the connected VIServer is vCenter Server ConfirmIsVCenter @@ -1782,13 +1672,6 @@ Function Get-KMServerStatus { .NOTES Author : Baoyin Qiao. Author email : bqiao@vmware.com - Version : 1.0 - - ==========Tested Against Environment========== - VMware vSphere Hypervisor(ESXi) Version : 6.5 - VMware vCenter Server Version : 6.5 - PowerCLI Version : PowerCLI 6.5 - PowerShell Version : 3.0 #> [CmdLetBinding()] @@ -1798,7 +1681,7 @@ Function Get-KMServerStatus { [String] $KMSClusterId ) - Begin { + Begin { # Confirm the connected VIServer is vCenter Server ConfirmIsVCenter @@ -1853,15 +1736,9 @@ Function Get-DefaultKMSCluster { .NOTES Author : Baoyin Qiao. Author email : bqiao@vmware.com - Version : 1.0 - - ==========Tested Against Environment========== - VMware vSphere Hypervisor(ESXi) Version : 6.5 - VMware vCenter Server Version : 6.5 - PowerCLI Version : PowerCLI 6.5 - PowerShell Version : 3.0 #> + write-warning "This cmdlet is deprecated and will be removed in future release. Use VMware.VimAutomation.Storage\Get-KmsCluster instead" # Confirm the connected VIServer is vCenter Server ConfirmIsVCenter @@ -1890,13 +1767,6 @@ Function Set-DefaultKMSCluster { .NOTES Author : Baoyin Qiao. Author email : bqiao@vmware.com - Version : 1.0 - - ==========Tested Against Environment========== - VMware vSphere Hypervisor(ESXi) Version : 6.5 - VMware vCenter Server Version : 6.5 - PowerCLI Version : PowerCLI 6.5 - PowerShell Version : 3.0 #> [CmdLetBinding()] @@ -1906,6 +1776,7 @@ Function Set-DefaultKMSCluster { [String] $KMSClusterId ) + write-warning "This cmdlet is deprecated and will be removed in future release. Use VMware.VimAutomation.Storage\Set-KmsCluster instead" # Confirm the connected VIServer is vCenter Server ConfirmIsVCenter @@ -1917,6 +1788,55 @@ Function Set-DefaultKMSCluster { $CM.MarkDefault($ProviderId) } +Function Set-VMCryptoUnlock { + <# + .SYNOPSIS + This cmdlet unlocks a locked vm + + .DESCRIPTION + This cmdlet unlocks a locked vm + + .PARAMETER VM + Specifies the VM you want to unlock + + .EXAMPLE + PS C:\> Get-VM |where {$_.locked}| Set-VMCryptoUnlock + + Unlock all locked vms + + .NOTES + Author : Fangying Zhang + Author email : fzhang@vmware.com + #> + + [CmdLetBinding()] + + param ( + [Parameter(Mandatory=$True,ValueFromPipeline=$True,ValueFromPipelinebyPropertyName=$True)] + [VMware.VimAutomation.ViCore.Types.V1.Inventory.VirtualMachine[]]$VM + ) + + Begin { + # Confirm the connected VIServer is vCenter Server + ConfirmIsVCenter + } + + Process { + foreach ($thisvm in $vm) { + if (!$thisvm.encrypted) { + write-warning "$thisvm is not encrypted, will skip $thisvm" + continue + } + if (!$thisvm.Locked) { + write-warning "$thisvm may not be locked!" + # $thisvm.locked could be false on old 6.5.0 build (bug 1931370), so do not skip $thisvm + } + write-verbose "try to CryptoUnlock $thisvm" + $thisvm.ExtensionData.CryptoUnlock() + } + } +} + Function ConfirmIsVCenter{ <# .SYNOPSIS From 13649b8e3584c2aaf4b954c15a30bbb5c8b8f658 Mon Sep 17 00:00:00 2001 From: simonfangyingzhang Date: Fri, 27 Apr 2018 04:32:55 +0100 Subject: [PATCH 10/22] Update VMware.VMEncryption.psm1 --- Modules/VMware.VMEncryption/VMware.VMEncryption.psm1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Modules/VMware.VMEncryption/VMware.VMEncryption.psm1 b/Modules/VMware.VMEncryption/VMware.VMEncryption.psm1 index 4085365..57734cf 100644 --- a/Modules/VMware.VMEncryption/VMware.VMEncryption.psm1 +++ b/Modules/VMware.VMEncryption/VMware.VMEncryption.psm1 @@ -831,7 +831,7 @@ Function Set-VMEncryptionKey { C:\PS>$VM|Set-VMEncryptionKey -KMSClusterId $KMSCluster.Id -Deep Deep rekeys the VM Home and all its disks using a new key. - The key is generted from the KMS whose clusterId is $KMSCluster.Id. + The key is generated from the KMS whose clusterId is $KMSCluster.Id. .NOTES This cmdlet assumes there is already a KMS in vCenter Server. If VM is not encrypted, the cmdlet quits. @@ -979,7 +979,7 @@ Function Set-VMDiskEncryptionKey { C:\PS>$HardDisk|$Set-VMEncryptionKey -VM $VM -KMSClusterId $KMSCluster.Id -Deep Deep rekeys all the disks of the $VM using a new key. - The key is generted from the KMS whose clusterId is $KMSCluster.Id. + The key is generated from the KMS whose clusterId is $KMSCluster.Id. .NOTES This cmdlet assumes there is already a KMS in vCenter Server. From 29719d6ca7cea9fdb160d44697d518135f6063ca Mon Sep 17 00:00:00 2001 From: simonfangyingzhang Date: Fri, 27 Apr 2018 04:42:18 +0100 Subject: [PATCH 11/22] Update VMware.VMEncryption.psm1 --- Modules/VMware.VMEncryption/VMware.VMEncryption.psm1 | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Modules/VMware.VMEncryption/VMware.VMEncryption.psm1 b/Modules/VMware.VMEncryption/VMware.VMEncryption.psm1 index 57734cf..d46d63b 100644 --- a/Modules/VMware.VMEncryption/VMware.VMEncryption.psm1 +++ b/Modules/VMware.VMEncryption/VMware.VMEncryption.psm1 @@ -81,6 +81,13 @@ New-VIProperty -Name Encrypted -ObjectType HardDisk -Value { $hardDisk.ExtensionData.Backing.KeyId -ne $null } -BasedOnExtensionProperty 'Backing.KeyId' -Force | Out-Null +New-VIProperty -Name KMSserver -ObjectType VMHost -Value { + Param ($VMHost) + if ($VMHost.CryptoSafe) { + $VMHost.ExtensionData.Runtime.CryptoKeyId.ProviderId.Id + } +} -BasedOnExtensionProperty 'Runtime.CryptoKeyId.ProviderId.Id' -Force | Out-Null + New-VIProperty -Name EncryptionKeyId -ObjectType HardDisk -Value { Param ($Disk) if ($Disk.Encrypted) { @@ -976,7 +983,7 @@ Function Set-VMDiskEncryptionKey { C:\PS>$KMSCluster = Get-KMSCluster | select -last 1 C:\PS>$VM = Get-VM -Name win2012 C:\PS>$HardDisk = get-vm $vm|Get-HardDisk - C:\PS>$HardDisk|$Set-VMEncryptionKey -VM $VM -KMSClusterId $KMSCluster.Id -Deep + C:\PS>$HardDisk|Set-VMDiskEncryptionKey -VM $VM -KMSClusterId $KMSCluster.Id -Deep Deep rekeys all the disks of the $VM using a new key. The key is generated from the KMS whose clusterId is $KMSCluster.Id. @@ -1681,7 +1688,7 @@ Function Get-KMServerStatus { [String] $KMSClusterId ) - Begin { + Begin { # Confirm the connected VIServer is vCenter Server ConfirmIsVCenter From 049e621fb63c3a7d9e0aca87d5a5a46053505ec7 Mon Sep 17 00:00:00 2001 From: simonfangyingzhang Date: Fri, 27 Apr 2018 04:45:44 +0100 Subject: [PATCH 12/22] Update VMware.VMEncryption.psm1 --- .../VMware.VMEncryption.psm1 | 23 +++++++------------ 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/Modules/VMware.VMEncryption/VMware.VMEncryption.psm1 b/Modules/VMware.VMEncryption/VMware.VMEncryption.psm1 index d46d63b..a7e47c2 100644 --- a/Modules/VMware.VMEncryption/VMware.VMEncryption.psm1 +++ b/Modules/VMware.VMEncryption/VMware.VMEncryption.psm1 @@ -69,18 +69,18 @@ New-VIProperty -Name vMotionEncryption -ObjectType VirtualMachine -Value { $VM.ExtensionData.Config.MigrateEncryption } -BasedOnExtensionProperty 'Config.MigrateEncryption' -Force | Out-Null -New-VIProperty -Name KMSserver -ObjectType VirtualMachine -Value { - Param ($VM) - if ($VM.Encrypted) { - $VM.EncryptionKeyId.ProviderId.Id - } -} -BasedOnExtensionProperty 'Config.KeyId' -Force | Out-Null - New-VIProperty -Name Encrypted -ObjectType HardDisk -Value { Param ($hardDisk) $hardDisk.ExtensionData.Backing.KeyId -ne $null } -BasedOnExtensionProperty 'Backing.KeyId' -Force | Out-Null +New-VIProperty -Name EncryptionKeyId -ObjectType HardDisk -Value { + Param ($Disk) + if ($Disk.Encrypted) { + $Disk.ExtensionData.Backing.KeyId + } +} -BasedOnExtensionProperty 'Backing.KeyId' -Force | Out-Null + New-VIProperty -Name KMSserver -ObjectType VMHost -Value { Param ($VMHost) if ($VMHost.CryptoSafe) { @@ -88,13 +88,6 @@ New-VIProperty -Name KMSserver -ObjectType VMHost -Value { } } -BasedOnExtensionProperty 'Runtime.CryptoKeyId.ProviderId.Id' -Force | Out-Null -New-VIProperty -Name EncryptionKeyId -ObjectType HardDisk -Value { - Param ($Disk) - if ($Disk.Encrypted) { - $Disk.ExtensionData.Backing.KeyId - } -} -BasedOnExtensionProperty 'Backing.KeyId' -Force | Out-Null - Function Enable-VMHostCryptoSafe { <# .SYNOPSIS @@ -983,7 +976,7 @@ Function Set-VMDiskEncryptionKey { C:\PS>$KMSCluster = Get-KMSCluster | select -last 1 C:\PS>$VM = Get-VM -Name win2012 C:\PS>$HardDisk = get-vm $vm|Get-HardDisk - C:\PS>$HardDisk|Set-VMDiskEncryptionKey -VM $VM -KMSClusterId $KMSCluster.Id -Deep + C:\PS>$HardDisk| Set-VMDiskEncryptionKey -VM $VM -KMSClusterId $KMSCluster.Id -Deep Deep rekeys all the disks of the $VM using a new key. The key is generated from the KMS whose clusterId is $KMSCluster.Id. From 9bd66f1a66bba48a5185deb81d30127de97ebcaa Mon Sep 17 00:00:00 2001 From: simonfangyingzhang Date: Fri, 27 Apr 2018 04:50:10 +0100 Subject: [PATCH 13/22] Update VMware.VMEncryption.psm1 --- Modules/VMware.VMEncryption/VMware.VMEncryption.psm1 | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Modules/VMware.VMEncryption/VMware.VMEncryption.psm1 b/Modules/VMware.VMEncryption/VMware.VMEncryption.psm1 index a7e47c2..7752274 100644 --- a/Modules/VMware.VMEncryption/VMware.VMEncryption.psm1 +++ b/Modules/VMware.VMEncryption/VMware.VMEncryption.psm1 @@ -69,6 +69,13 @@ New-VIProperty -Name vMotionEncryption -ObjectType VirtualMachine -Value { $VM.ExtensionData.Config.MigrateEncryption } -BasedOnExtensionProperty 'Config.MigrateEncryption' -Force | Out-Null +New-VIProperty -Name KMSserver -ObjectType VirtualMachine -Value { + Param ($VM) + if ($VM.Encrypted) { + $VM.EncryptionKeyId.ProviderId.Id + } +} -BasedOnExtensionProperty 'Config.KeyId' -Force | Out-Null + New-VIProperty -Name Encrypted -ObjectType HardDisk -Value { Param ($hardDisk) $hardDisk.ExtensionData.Backing.KeyId -ne $null From 3b44fbcf204ab4484471627b6450f63d17492001 Mon Sep 17 00:00:00 2001 From: simonfangyingzhang Date: Fri, 27 Apr 2018 04:53:24 +0100 Subject: [PATCH 14/22] Update VMware.VMEncryption.psd1 --- Modules/VMware.VMEncryption/VMware.VMEncryption.psd1 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Modules/VMware.VMEncryption/VMware.VMEncryption.psd1 b/Modules/VMware.VMEncryption/VMware.VMEncryption.psd1 index 45b17c1..95b678f 100644 --- a/Modules/VMware.VMEncryption/VMware.VMEncryption.psd1 +++ b/Modules/VMware.VMEncryption/VMware.VMEncryption.psd1 @@ -68,7 +68,7 @@ RequiredModules = @( NestedModules = @('VMware.VMEncryption.psm1') # Functions to export from this module -FunctionsToExport = '*-*' +FunctionsToExport = '*' # Cmdlets to export from this module CmdletsToExport = '*' @@ -95,3 +95,4 @@ AliasesToExport = '*' # DefaultCommandPrefix = '' } + From 60aafba7ae2e91bb52c8be9704f4ebac65f48e0e Mon Sep 17 00:00:00 2001 From: simonfangyingzhang Date: Fri, 27 Apr 2018 05:03:22 +0100 Subject: [PATCH 15/22] Update VMware.VMEncryption.psd1 --- Modules/VMware.VMEncryption/VMware.VMEncryption.psd1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Modules/VMware.VMEncryption/VMware.VMEncryption.psd1 b/Modules/VMware.VMEncryption/VMware.VMEncryption.psd1 index 95b678f..1213466 100644 --- a/Modules/VMware.VMEncryption/VMware.VMEncryption.psd1 +++ b/Modules/VMware.VMEncryption/VMware.VMEncryption.psd1 @@ -12,7 +12,7 @@ # RootModule = '' # Version number of this module. -ModuleVersion = '1.1' +ModuleVersion = '1.0' # ID used to uniquely identify this module GUID = 'f9592e48-6cd3-494e-891b-ee10ee9f7018' From 95138e128f9bb1d055aee4073e86cf32726b182c Mon Sep 17 00:00:00 2001 From: simonfangyingzhang Date: Fri, 27 Apr 2018 05:10:09 +0100 Subject: [PATCH 16/22] Update VMware.VMEncryption.psd1 --- Modules/VMware.VMEncryption/VMware.VMEncryption.psd1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Modules/VMware.VMEncryption/VMware.VMEncryption.psd1 b/Modules/VMware.VMEncryption/VMware.VMEncryption.psd1 index 1213466..95b678f 100644 --- a/Modules/VMware.VMEncryption/VMware.VMEncryption.psd1 +++ b/Modules/VMware.VMEncryption/VMware.VMEncryption.psd1 @@ -12,7 +12,7 @@ # RootModule = '' # Version number of this module. -ModuleVersion = '1.0' +ModuleVersion = '1.1' # ID used to uniquely identify this module GUID = 'f9592e48-6cd3-494e-891b-ee10ee9f7018' From f4ba11fe7558fb4ba2f95cb580cad81549342c8a Mon Sep 17 00:00:00 2001 From: jrodsguitar Date: Sun, 29 Apr 2018 12:27:58 -0700 Subject: [PATCH 17/22] Added Remove-HVMachine to Export-ModuleMember --- Modules/VMware.Hv.Helper/VMware.HV.Helper.psm1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Modules/VMware.Hv.Helper/VMware.HV.Helper.psm1 b/Modules/VMware.Hv.Helper/VMware.HV.Helper.psm1 index 9d84561..5d20bb6 100644 --- a/Modules/VMware.Hv.Helper/VMware.HV.Helper.psm1 +++ b/Modules/VMware.Hv.Helper/VMware.HV.Helper.psm1 @@ -10887,4 +10887,4 @@ function remove-hvsite { [System.gc]::collect() } -Export-ModuleMember Add-HVDesktop,Add-HVRDSServer,Connect-HVEvent,Disconnect-HVEvent,Get-HVPoolSpec,Get-HVInternalName, Get-HVEvent,Get-HVFarm,Get-HVFarmSummary,Get-HVPool,Get-HVPoolSummary,Get-HVMachine,Get-HVMachineSummary,Get-HVQueryResult,Get-HVQueryFilter,New-HVFarm,New-HVPool,Remove-HVFarm,Remove-HVPool,Set-HVFarm,Set-HVPool,Start-HVFarm,Start-HVPool,New-HVEntitlement,Get-HVEntitlement,Remove-HVEntitlement, Set-HVMachine, New-HVGlobalEntitlement, Remove-HVGlobalEntitlement, Get-HVGlobalEntitlement, Set-HVApplicationIcon, Remove-HVApplicationIcon, Get-HVGlobalSettings, Set-HVGlobalSettings, Set-HVGlobalEntitlement, Get-HVResourceStructure, Get-hvlocalsession, Get-HVGlobalSession, Reset-HVMachine, Get-HVHealth, new-hvpodfederation, remove-hvpodfederation, get-hvpodfederation, register-hvpod, unregister-hvpod, set-hvpodfederation,get-hvsite,new-hvsite,set-hvsite,remove-hvsite +Export-ModuleMember Add-HVDesktop,Add-HVRDSServer,Connect-HVEvent,Disconnect-HVEvent,Get-HVPoolSpec,Get-HVInternalName, Get-HVEvent,Get-HVFarm,Get-HVFarmSummary,Get-HVPool,Get-HVPoolSummary,Get-HVMachine,Get-HVMachineSummary,Get-HVQueryResult,Get-HVQueryFilter,New-HVFarm,New-HVPool,Remove-HVFarm,Remove-HVPool,Set-HVFarm,Set-HVPool,Start-HVFarm,Start-HVPool,New-HVEntitlement,Get-HVEntitlement,Remove-HVEntitlement, Set-HVMachine, New-HVGlobalEntitlement, Remove-HVGlobalEntitlement, Get-HVGlobalEntitlement, Set-HVApplicationIcon, Remove-HVApplicationIcon, Get-HVGlobalSettings, Set-HVGlobalSettings, Set-HVGlobalEntitlement, Get-HVResourceStructure, Get-hvlocalsession, Get-HVGlobalSession, Reset-HVMachine, Remove-HVMachine, Get-HVHealth, new-hvpodfederation, remove-hvpodfederation, get-hvpodfederation, register-hvpod, unregister-hvpod, set-hvpodfederation,get-hvsite,new-hvsite,set-hvsite,remove-hvsite From 8694c402108ac7a67f5cc5ad6feac4c74b4ff18b Mon Sep 17 00:00:00 2001 From: William Lam Date: Mon, 30 Apr 2018 05:22:46 -0700 Subject: [PATCH 18/22] Parentless Instant Clone for vSphere 6.7 --- Modules/InstantClone/InstantClone.psm1 | 68 ++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 Modules/InstantClone/InstantClone.psm1 diff --git a/Modules/InstantClone/InstantClone.psm1 b/Modules/InstantClone/InstantClone.psm1 new file mode 100644 index 0000000..bd36545 --- /dev/null +++ b/Modules/InstantClone/InstantClone.psm1 @@ -0,0 +1,68 @@ +Function New-InstantClone { +<# + .NOTES + =========================================================================== + Created by: William Lam + Date: Apr 29, 2018 + Organization: VMware + Blog: www.virtuallyghetto.com + Twitter: @lamw + =========================================================================== + .SYNOPSIS + This function demonstrates the use of the new "Parentless" Instant Clone + API that was introduced in vSphere 6.7 + .DESCRIPTION + Function to create new "Parentless" Instant Clones in vSphere 6.7 + .EXAMPLE + $SourceVM = "Foo" + $newVMName = Foo-IC-1 + $guestCustomizationValues = @{ + "guestinfo.ic.hostname" = $newVMName + "guestinfo.ic.ipaddress" = "192.168.30.10" + "guestinfo.ic.netmask" = "255.255.255.0" + "guestinfo.ic.gateway" = "192.168.30.1" + "guestinfo.ic.dns" = "192.168.30.1" + } + New-InstantClone -SourceVM $SourceVM -DestinationVM $newVMName -CustomizationFields $guestCustomizationValues + .NOTES + Make sure that you have both a vSphere 6.7 env (VC/ESXi) as well as + as the latest PowerCLI 10.1 installed which is reuqired to use vSphere 6.7 APIs +#> + param( + [Parameter(Mandatory=$true)][String]$SourceVM, + [Parameter(Mandatory=$true)][String]$DestinationVM, + [Parameter(Mandatory=$true)][Hashtable]$CustomizationFields + ) + $vm = Get-VM -Name $SourceVM + + $config = @() + $CustomizationFields.GetEnumerator() | Foreach-Object { + $optionValue = New-Object VMware.Vim.OptionValue + $optionValue.Key = $_.Key + $optionValue.Value = $_.Value + $config += $optionValue + } + + # SourceVM must either be running or running but in Frozen State + if($vm.PowerState -ne "PoweredOn") { + Write-Host -ForegroundColor Red "Instant Cloning is only supported on a PoweredOn or Frozen VM" + break + } + + # SourceVM == Powered On + if((Get-VM $SourceVM).ExtensionData.Runtime.InstantCloneFrozen -eq $false) { + Write-Host -ForegroundColor Red "Instant Cloning from a PoweredOn VM has not been implemented" + break + } + + $spec = New-Object VMware.Vim.VirtualMachineInstantCloneSpec + $locationSpec = New-Object VMware.Vim.VirtualMachineRelocateSpec + $spec.Config = $config + $spec.Location = $locationSpec + $spec.Name = $DestinationVM + + Write-Host "Creating Instant Clone $DestinationVM ..." + $task = $vm.ExtensionData.InstantClone_Task($spec) + $task1 = Get-Task -Id ("Task-$($task.value)") + $task1 | Wait-Task | Out-Null +} \ No newline at end of file From 60217aaa5c584347c33aaa86be0ed85d8cbeca13 Mon Sep 17 00:00:00 2001 From: cmcmahonVMW <39139413+cmcmahonVMW@users.noreply.github.com> Date: Thu, 10 May 2018 00:29:15 -0400 Subject: [PATCH 19/22] Updates needed for v2.0 In v2.0 of the tool, the URI for Get-XVCMStatus changed from /api/ping to /api/status, updated line 15. In v2.0 of the tool, there were a number of changes necessary for New-XVCMRequest. Updated the Notes on Lines 145-173 to reflect new parameters, changed behavior and removed parameters. Added $opType on line 176 and 202 for the Operation type new to v2.0. Removed line 181 and 196 for Source Cluster because it is no longer needed. Modified $DstCluster to accept null and removed the String Type definition to allow null to not be converted or the task creation will fail because it expects null as the assigned value. Added $DstHost to line 184 and 199 to allow destination host input to override $DstCluster. --- Modules/CrossvCentervmotion/XVM.psm1 | 32 +++++++++++++++++----------- 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/Modules/CrossvCentervmotion/XVM.psm1 b/Modules/CrossvCentervmotion/XVM.psm1 index aef65c8..cb9d225 100644 --- a/Modules/CrossvCentervmotion/XVM.psm1 +++ b/Modules/CrossvCentervmotion/XVM.psm1 @@ -1,4 +1,4 @@ -Function Get-XVCMStatus { +Function Get-XVCMStatus { <# .NOTES =========================================================================== @@ -12,7 +12,7 @@ .EXAMPLE Get-XVCMStatus #> - $Uri = "http://localhost:8080/api/ping" + $Uri = "http://localhost:8080/api/status" #Updated for 2.0, Old: "http://localhost:8080/api/ping" $results = Invoke-WebRequest -Uri $Uri -Method GET -TimeoutSec 5 @@ -142,7 +142,9 @@ Function New-XVCMRequest { =========================================================================== .DESCRIPTION This function initiates a migration request - .PARAMETER SrcSite + .PARAMETER opType + The type of task, Relocate or Clone + .PARAMETER SrcSite The name of the source vCenter Server .PARAMETER DstSite The name of the destination vCenter Server @@ -151,31 +153,35 @@ Function New-XVCMRequest { .PARAMETER DstDatacenter The name of the destination vSphere Datacenter .PARAMETER SrcCluster - The name of the source vSphere Cluster + .PARAMETER DstCluster - The name of the destination vSphere Cluster + The name of the destination vSphere Cluster, set to null if DstHost is defined .PARAMETER DstDatastore The name of the destination Datastore - .PARAMETER srcVMs + .PARAMETER DstHost + The name of the destination host. Set to null if DstCluster is defined + .PARAMETER srcVMs List of VMs to migrate .PARAMETER NetworkMapping Hash table of the VM network mappings between your source and destination vCenter Server .EXAMPLE - New-XVCMRequest -SrcSite SiteA -DstSite SiteB ` + New-XVCMRequest -opType Relocate -SrcSite SiteA -DstSite SiteB ` -SrcDatacenter Datacenter-SiteA -DstDatacenter Datacenter-SiteB ` - -SrcCluster Palo-Alto -DstCluster Santa-Barbara ` + -DstCluster $null -DstHost VMhost1.test.lab ` -DstDatastore vsanDatastore ` -srcVMs @("PhotonOS-01","PhotonOS-02","PhotonOS-03","PhotonOS-04") ` -NetworkMapping @{"DVPG-VM Network 1"="DVPG-Internal Network";"DVPG-VM Network 2"="DVPG-External Network"} #> param( + [Parameter(Mandatory=$true)][String]$opType, #Added by CPM for 2.0 [Parameter(Mandatory=$true)][String]$SrcSite, [Parameter(Mandatory=$true)][String]$DstSite, [Parameter(Mandatory=$true)][String]$SrcDatacenter, [Parameter(Mandatory=$true)][String]$DstDatacenter, - [Parameter(Mandatory=$true)][String]$SrcCluster, - [Parameter(Mandatory=$true)][String]$DstCluster, + #[Parameter(Mandatory=$true)][String]$SrcCluster, #Removed by CPM for 2.0 + [Parameter(Mandatory=$true)][AllowNull()] $DstCluster, #Added [AllowNull()], removed [String] by CPM for 2.0 [Parameter(Mandatory=$true)][String]$DstDatastore, + [Parameter(Mandatory=$true)][AllowNull()] $DstHost, #Added by CPM for 2.0 [Parameter(Mandatory=$true)][String[]]$srcVMs, [Parameter(Mandatory=$true)][Hashtable]$NetworkMapping ) @@ -187,11 +193,13 @@ Function New-XVCMRequest { "targetSite"=$DstSite; "sourceDatacenter"=$SrcDatacenter; "targetDatacenter"=$dstDatacenter; - "sourceCluster"=$SrcCluster; + #"sourceCluster"=$SrcCluster; #Removed by CPM for 2.0 "targetCluster"=$DstCluster; "targetDatastore"=$DstDatastore; + "targetHost"=$DstHost; #Added by CPM for 2.0 "networkMap"=$NetworkMapping; "vmList"=$srcVMs; + "operationType"=$opType; #Added by CPM for 2.0 } $body = $body | ConvertTo-Json @@ -287,4 +295,4 @@ Function Get-VMNetwork { } } $results -} \ No newline at end of file +} From 7c28fbc8941587b00121eb284390c1286de6e0f5 Mon Sep 17 00:00:00 2001 From: William Lam Date: Sun, 20 May 2018 05:12:50 -0700 Subject: [PATCH 20/22] Adding logic to handle PoweredOn Source VM --- Modules/InstantClone/InstantClone.psm1 | 46 +++++++++++++++++++++----- 1 file changed, 38 insertions(+), 8 deletions(-) diff --git a/Modules/InstantClone/InstantClone.psm1 b/Modules/InstantClone/InstantClone.psm1 index bd36545..b67d0e4 100644 --- a/Modules/InstantClone/InstantClone.psm1 +++ b/Modules/InstantClone/InstantClone.psm1 @@ -51,15 +51,45 @@ # SourceVM == Powered On if((Get-VM $SourceVM).ExtensionData.Runtime.InstantCloneFrozen -eq $false) { - Write-Host -ForegroundColor Red "Instant Cloning from a PoweredOn VM has not been implemented" - break - } - $spec = New-Object VMware.Vim.VirtualMachineInstantCloneSpec - $locationSpec = New-Object VMware.Vim.VirtualMachineRelocateSpec - $spec.Config = $config - $spec.Location = $locationSpec - $spec.Name = $DestinationVM + # Retrieve all Network Adapters for SourceVM + $vmNetworkAdapters = @() + $devices = $vm.ExtensionData.Config.Hardware.Device + foreach ($device in $devices) { + if($device -is [VMware.Vim.VirtualEthernetCard]) { + $vmNetworkAdapters += $device + } + } + + $spec = New-Object VMware.Vim.VirtualMachineInstantCloneSpec + $locationSpec = New-Object VMware.Vim.VirtualMachineRelocateSpec + + # Disconect all NICs for new Instant Clone to ensure no dupe addresses on network + # post-Instant Clone workflow needs to renable after uypdating GuestOS + foreach ($vmNetworkAdapter in $vmNetworkAdapters) { + $networkName = $vmNetworkAdapter.backing.deviceName + $deviceConfigSpec = New-Object VMware.Vim.VirtualDeviceConfigSpec + $deviceConfigSpec.Operation = "edit" + $deviceConfigSpec.Device = $vmNetworkAdapter + $deviceConfigSpec.Device.backing = New-Object VMware.Vim.VirtualEthernetCardNetworkBackingInfo + $deviceConfigSpec.device.backing.deviceName = $networkName + $connectable = New-Object VMware.Vim.VirtualDeviceConnectInfo + $connectable.MigrateConnect = "disconnect" + $deviceConfigSpec.Device.Connectable = $connectable + $locationSpec.DeviceChange += $deviceConfigSpec + } + + $spec.Config = $config + $spec.Location = $locationSpec + $spec.Name = $DestinationVM + # SourceVM == Frozen + } else { + $spec = New-Object VMware.Vim.VirtualMachineInstantCloneSpec + $locationSpec = New-Object VMware.Vim.VirtualMachineRelocateSpec + $spec.Config = $config + $spec.Location = $locationSpec + $spec.Name = $DestinationVM + } Write-Host "Creating Instant Clone $DestinationVM ..." $task = $vm.ExtensionData.InstantClone_Task($spec) From fb5c9e248a5b6cbfc8201d9cc76bc9739916f925 Mon Sep 17 00:00:00 2001 From: William Lam Date: Sun, 20 May 2018 06:39:49 -0700 Subject: [PATCH 21/22] Fixing typo in poweredOn string --- Modules/InstantClone/InstantClone.psm1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Modules/InstantClone/InstantClone.psm1 b/Modules/InstantClone/InstantClone.psm1 index b67d0e4..a54865a 100644 --- a/Modules/InstantClone/InstantClone.psm1 +++ b/Modules/InstantClone/InstantClone.psm1 @@ -44,7 +44,7 @@ } # SourceVM must either be running or running but in Frozen State - if($vm.PowerState -ne "PoweredOn") { + if($vm.PowerState -ne "poweredOn") { Write-Host -ForegroundColor Red "Instant Cloning is only supported on a PoweredOn or Frozen VM" break } From aaae686d7cf3687a5a670f0156693bd36ce888fa Mon Sep 17 00:00:00 2001 From: Kyle Ruddy Date: Mon, 21 May 2018 11:50:19 -0400 Subject: [PATCH 22/22] Adding Per-VM EVC Module Per-VM EVC functionality is available through the vSphere API. This module adds the ability to manage these settings through high-level functions like Get-VMEvcMode, Set-VMEvcMode, Remove-VMEvcMode --- Modules/PerVMEVC/PerVMEVC.psm1 | 192 +++++++++++++++++++++++++++++++++ 1 file changed, 192 insertions(+) create mode 100644 Modules/PerVMEVC/PerVMEVC.psm1 diff --git a/Modules/PerVMEVC/PerVMEVC.psm1 b/Modules/PerVMEVC/PerVMEVC.psm1 new file mode 100644 index 0000000..05f8390 --- /dev/null +++ b/Modules/PerVMEVC/PerVMEVC.psm1 @@ -0,0 +1,192 @@ +function Get-VMEvcMode { +<# +.SYNOPSIS + Gathers information on the EVC status of a VM +.DESCRIPTION + Will provide the EVC status for the specified VM +.NOTES + Author: Kyle Ruddy, @kmruddy, thatcouldbeaproblem.com +.PARAMETER Name + VM name which the function should be ran against +.EXAMPLE + Get-VMEvcMode -Name vmName + Retreives the EVC status of the provided VM +#> +[CmdletBinding()] + param( + [Parameter(Mandatory=$true,Position=0,ValueFromPipelineByPropertyName=$true)] + $Name + ) + + Process { + $evVM = @() + + if ($name -is [string]) {$evVM += Get-VM -Name $Name -ErrorAction SilentlyContinue} + elseif ($name -is [array]) { + + if ($name[0] -is [string]) { + $name | foreach { + $evVM += Get-VM -Name $_ -ErrorAction SilentlyContinue + } + } + elseif ($name[0] -is [VMware.VimAutomation.ViCore.Impl.V1.Inventory.InventoryItemImpl]) {$evVM = $name} + + } + elseif ($name -is [VMware.VimAutomation.ViCore.Impl.V1.Inventory.InventoryItemImpl]) {$evVM += $name} + + if ($evVM -eq $null) {Write-Warning "No VMs found."} + else { + $output = @() + foreach ($v in $evVM) { + + $report = "" | select Name,EVCMode + $report.Name = $v.Name + $report.EVCMode = $v.ExtensionData.Runtime.MinRequiredEVCModeKey + $output += $report + + } + + return $output + + } + + } + +} + +function Remove-VMEvcMode { +<# +.SYNOPSIS + Removes the EVC status of a VM +.DESCRIPTION + Will remove the EVC status for the specified VM +.NOTES + Author: Kyle Ruddy, @kmruddy, thatcouldbeaproblem.com +.PARAMETER Name + VM name which the function should be ran against +.EXAMPLE + Remove-VMEvcMode -Name vmName + Removes the EVC status of the provided VM +#> +[CmdletBinding()] + param( + [Parameter(Mandatory=$true,Position=0,ValueFromPipelineByPropertyName=$true)] + $Name + ) + + Process { + $evVM = @() + $updateVM = @() + + if ($name -is [string]) {$evVM += Get-VM -Name $Name -ErrorAction SilentlyContinue} + elseif ($name -is [array]) { + + if ($name[0] -is [string]) { + $name | foreach { + $evVM += Get-VM -Name $_ -ErrorAction SilentlyContinue + } + } + elseif ($name[0] -is [VMware.VimAutomation.ViCore.Impl.V1.Inventory.InventoryItemImpl]) {$evVM = $name} + + } + elseif ($name -is [VMware.VimAutomation.ViCore.Impl.V1.Inventory.InventoryItemImpl]) {$evVM += $name} + + if ($evVM -eq $null) {Write-Warning "No VMs found."} + else { + foreach ($v in $evVM) { + + if (($v.HardwareVersion -ge 'vmx-14' -and $v.PowerState -eq 'PoweredOff') -or ($v.Version -ge 'v14' -and $v.PowerState -eq 'PoweredOff')) { + + $v.ExtensionData.ApplyEvcModeVM_Task($null, $true) | Out-Null + $updateVM += $v.Name + + } + else {Write-Warning $v.Name + " does not have the minimum requirements of being Hardware Version 14 and powered off."} + + } + + if ($updateVM) { + + Start-Sleep -Seconds 2 + Get-VMEvcMode -Name $updateVM + + } + + } + + } + +} + +function Set-VMEvcMode { +<# +.SYNOPSIS + Configures the EVC status of a VM +.DESCRIPTION + Will configure the EVC status for the specified VM +.NOTES + Author: Kyle Ruddy, @kmruddy, thatcouldbeaproblem.com +.PARAMETER Name + VM name which the function should be ran against +.PARAMETER EvcMode + The EVC Mode key which should be set +.EXAMPLE + Set-VMEvcMode -Name vmName -EvcMode intel-sandybridge + Configures the EVC status of the provided VM to be 'intel-sandybridge' +#> +[CmdletBinding()] + param( + [Parameter(Mandatory=$true,Position=0,ValueFromPipelineByPropertyName=$true)] + $Name, + [Parameter(Mandatory=$true,Position=1)] + [ValidateSet("intel-merom","intel-penryn","intel-nehalem","intel-westmere","intel-sandybridge","intel-ivybridge","intel-haswell","intel-broadwell","intel-skylake","amd-rev-e","amd-rev-f","amd-greyhound-no3dnow","amd-greyhound","amd-bulldozer","amd-piledriver","amd-steamroller","amd-zen")] + $EvcMode + ) + + Process { + $evVM = @() + $updateVM = @() + + if ($name -is [string]) {$evVM += Get-VM -Name $Name -ErrorAction SilentlyContinue} + elseif ($name -is [array]) { + + if ($name[0] -is [string]) { + $name | foreach { + $evVM += Get-VM -Name $_ -ErrorAction SilentlyContinue + } + } + elseif ($name[0] -is [VMware.VimAutomation.ViCore.Impl.V1.Inventory.InventoryItemImpl]) {$evVM = $name} + + } + elseif ($name -is [VMware.VimAutomation.ViCore.Impl.V1.Inventory.InventoryItemImpl]) {$evVM += $name} + + if ($evVM -eq $null) {Write-Warning "No VMs found."} + else { + + $si = Get-View ServiceInstance + $evcMask = $si.Capability.SupportedEvcMode | where-object {$_.key -eq $EvcMode} | select -ExpandProperty FeatureMask + + foreach ($v in $evVM) { + + if (($v.HardwareVersion -ge 'vmx-14' -and $v.PowerState -eq 'PoweredOff') -or ($v.Version -ge 'v14' -and $v.PowerState -eq 'PoweredOff')) { + + $v.ExtensionData.ApplyEvcModeVM_Task($evcMask, $true) | Out-Null + $updateVM += $v.Name + + } + else {Write-Warning $v.Name + " does not have the minimum requirements of being Hardware Version 14 and powered off."} + + } + + if ($updateVM) { + + Start-Sleep -Seconds 2 + Get-VMEvcMode -Name $updateVM + + } + + } + + } + +}