-
Notifications
You must be signed in to change notification settings - Fork 0
/
get-drsrulesicc.ps1
78 lines (61 loc) · 2.18 KB
/
get-drsrulesicc.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
74
75
76
77
78
<#PSScriptInfo
.DESCRIPTION
List all host DRS rules using PowerCLI
.VERSION
0.0.1
.AUTHOR
Ben Brouhard @benbjamin24
.TAGS
VMware PowerCLI
.Dependency
DRSRules module
https://github.com/PowerCLIGoodies/DRSRule/b
#>
##list all clusters and DRSrules
Function get-alldrsrules {
foreach ($cluster in get-cluster) {
Write-Host "$cluster"
Get-DrsRule -Cluster $cluster
Get-DrsVMGroup -Cluster $cluster
Get-DrsVMToVMHostRule -Cluster $cluster
Get-DrsVMToVMRule -Cluster $cluster
Write-Host " "
}
}
function export-alldrsrules {
foreach ($cluster in get-cluster) {
Export-DrsRule -Cluster $cluster -Path C:\temp\$cluster-export.json
}
}
# Queries Database for hostgroup records and creates a host group if missing and add the hosts.
$DRShostrulesquery = "select * from vm_drsrules
where Ruletype = 'ClusterHostGroup'"
$DRSHOSTGROUPS = BGMGT-querysql $DRShostrulesquery
foreach ($HOSTGROUP in $DRSHOSTGROUPS ) {
if (!(Get-DrsVMHostGroup -Name $HOSTGROUP.RuleName)) {
$DRShostmemberquery = "select member from vm_drsrules_members
where RuleName = '$($HOSTGROUP.RuleName)'"
$DRSHOSTMEMBERS = BGMGT-querysql $DRShostmemberquery
foreach ($MEMBERS in $DRSHOSTMEMBERS){
$MEMBER += $MEMBERS.Member
}
New-DrsVMHostGroup -Name $HOSTGROUP.RuleName -VMHost $MEMBER -Cluster $HOSTGROUP.cluster
}
}
get
#export-alldrsrules
# Queries Database for hostgroup records and creates a host group if missing and add the hosts.
$DRSVMAFrulesquery = "select * from vm_drsrules
where Ruletype = 'vmaffintiy'"
$DRSHOSTGROUPS = BGMGT-querysql $DRShostrulesquery
foreach ($HOSTGROUP in $DRSHOSTGROUPS ) {
if (!(Get-DrsVMHostGroup -Name $HOSTGROUP.RuleName)) {
$DRShostmemberquery = "select member from vm_drsrules_members
where RuleName = '$($HOSTGROUP.RuleName)'"
$DRSHOSTMEMBERS = BGMGT-querysql $DRShostmemberquery
foreach ($MEMBERS in $DRSHOSTMEMBERS){
$MEMBER += $MEMBERS.Member
}
New-DrsVMHostGroup -Name $HOSTGROUP.RuleName -VMHost $MEMBER -Cluster $HOSTGROUP.cluster
}
}