From 1b7ea8034219008f6eff8072276b6ba2e020abb1 Mon Sep 17 00:00:00 2001 From: Doug Taliaferro Date: Fri, 11 Oct 2019 09:30:38 -0400 Subject: [PATCH] Create Set-ClusterDpm.ps1 Configures Distributed Power Managment (DPM) --- Scripts/Set-ClusterDpm.ps1 | 63 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 Scripts/Set-ClusterDpm.ps1 diff --git a/Scripts/Set-ClusterDpm.ps1 b/Scripts/Set-ClusterDpm.ps1 new file mode 100644 index 0000000..82292c2 --- /dev/null +++ b/Scripts/Set-ClusterDpm.ps1 @@ -0,0 +1,63 @@ +<# +.NOTES + Script name: Set-ClusterDpm.ps1 + Created on: 10/10/2019 + Author: Doug Taliaferro, @virtually_doug + Description: Configures Distributed Power Management (DPM) on a cluster. + Dependencies: None known + + ===Tested Against Environment==== + vSphere Version: 6.7 + PowerCLI Version: 11.3.0 + PowerShell Version: 5.1 + OS Version: Windows 7, 10 + Keyword: Cluster, DPM +.SYNOPSIS + Configures Distributed Power Management (DPM). + +.DESCRIPTION + Enables/disables Distributed Power Management (DPM) for one or more clusters and optionally sets the automation level. + +.PARAMETER Clusters + Specifies the name of the cluster(s) you want to configure. + +.PARAMETER DpmEnabled + Indicates whether Distributed Power Management (DPM) should be enabled/disabled. + +.PARAMETER DpmAutomationLevel + Specifies the Distributed Power Management (DPM) automation level. The valid values are 'automated' and 'manual'. + +.EXAMPLE + Set-ClusterDpm -Cluster 'Cluster01' -DpmEnabled:$true + +.EXAMPLE + Get-Cluster | Set-ClusterDpm -DpmEnabled:$true -DpmAutomationLevel 'automated' +#> +[CmdletBinding()] +param ( + [Parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true)] + [Alias('Name')] + [string[]]$Clusters, + + [Parameter(Mandatory=$true)] + [bool]$DpmEnabled, + + [Parameter(Mandatory = $false)] + [ValidateSet('automated','manual')] + [string]$DpmAutomationLevel +) +Begin { + # Create a configuration spec + $spec = New-Object VMware.Vim.ClusterConfigSpecEx + $spec.dpmConfig = New-Object VMware.Vim.ClusterDpmConfigInfo + $spec.dpmConfig.enabled = $DpmEnabled + if ($DpmAutomationLevel) { + $spec.dpmConfig.defaultDpmBehavior = $DpmAutomationLevel + } +} +Process { + ForEach ($cluster in $Clusters) { + # Configure the cluster + (Get-Cluster $cluster).ExtensionData.ReconfigureComputeResource_Task($spec, $true) + } +}