-
Notifications
You must be signed in to change notification settings - Fork 50
/
Copy pathSet-pDRS.ps1
74 lines (58 loc) · 1.84 KB
/
Set-pDRS.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#Enable/Disable Predictive DRS
Get-cluster | where {$_.ExtensionData.ConfigurationEx.ProactiveDRsConfig.Enabled -eq $False}
#check to see if DRS is enabled
#
$cls = Get-cluster | Get-View
$spec = New-Object VMware.Vim.ClusterConfigSpecEx
$spec.ProactiveDrsConfig = New-Object VMware.Vim.ClusterProactiveDrsConfigInfo
$spec.ProactiveDrsConfig.Enabled = $true
$cls.ReconfigureComputeResource_Task($spec, $true)
Function Get-pDRS {
param (
[Parameter(Position = 0,
Mandatory = $true,
ValueFromPipeline = $true)]
$Cluster
)
Begin {}
Process {Get-Cluster | Select Name, @{Name="pDRS_Status";Expression={$_.ExtensionData.ConfigurationEx.ProactiveDRSConfig.Enabled}} }
End {}
}
Get-pDRS -Cluster (Get-Cluster)
Function Set-pDRS
{
param (
[Parameter(Position = 0,
Mandatory = $true,
ValueFromPipeline = $true)]
$Cluster,
[Parameter(ParameterSetName='Basic', Mandatory = $false)]
[switch]$Enabled,
[Parameter(ParameterSetName = 'Detailed', Mandatory = $false)]
[switch] $Disabled
)
Begin {}
Process {
foreach ($cls in $cluster) {
switch ($Cls.gettype().name) {
"ClusterImpl" {
$cls = $cls | get-view
}
"String" {
$cls = Get-Cluster $cls | Get-View
}
}
$spec = New-Object VMware.Vim.ClusterConfigSpecEx
$spec.ProactiveDrsConfig = New-Object VMware.Vim.ClusterProactiveDrsConfigInfo
if ($Enabled) {
$spec.ProactiveDrsConfig.Enabled = $true
} else {
$spec.ProactiveDrsConfig.Enabled = $false
}
$cls.ReconfigureComputeResource_Task($spec, $true) | out-null
$cls.UpdateViewData()
$cls | select Name, @{Name="pDRS_Status";Expression={$_.ConfigurationEx.ProactiveDRSConfig.Enabled}}
}
}
End {}
}