Add scripts for creating cluster groups and affinity rules.
These scripts create DRS groups for virtual machines and hosts, and host affinity rules.
This commit is contained in:
43
Scripts/New-ClusterHostGroup.ps1
Normal file
43
Scripts/New-ClusterHostGroup.ps1
Normal file
@@ -0,0 +1,43 @@
|
||||
<#
|
||||
.NOTES
|
||||
===========================================================================
|
||||
Script name: New-ClusterHostGroup.ps1
|
||||
Created on: 2016-10-25
|
||||
Author: Peter D. Jorgensen (@pjorg, pjorg.com)
|
||||
Dependencies: None known
|
||||
===Tested Against Environment====
|
||||
vSphere Version: 5.5, 6.0
|
||||
PowerCLI Version: PowerCLI 6.5R1
|
||||
PowerShell Version: 5.0
|
||||
OS Version: Windows 10, Windows 7
|
||||
===========================================================================
|
||||
.DESCRIPTION
|
||||
Creates a DRS Host Group in a vSphere cluster.
|
||||
.Example
|
||||
$ProdCluster = Get-Cluster *prod*
|
||||
$OddHosts = $ProdCluster | Get-VMHost | ?{ $_.Name -match 'esxi-\d*[13579]+.\lab\.local' }
|
||||
.\New-ClusterHostGroup.ps1 -Name 'OddProdHosts' -Cluster $ProdCluster -VMHost $OddHosts
|
||||
#>
|
||||
[CmdletBinding()]
|
||||
Param(
|
||||
[Parameter(Mandatory=$True,Position=1)]
|
||||
[String]$Name,
|
||||
[Parameter(Mandatory=$True,ValueFromPipeline=$True,Position=2)]
|
||||
[VMware.VimAutomation.ViCore.Types.V1.Inventory.Cluster]$Cluster,
|
||||
[Parameter(Mandatory=$False,Position=3)]
|
||||
[VMware.VimAutomation.ViCore.Types.V1.Inventory.VMHost[]]$VMHost
|
||||
)
|
||||
|
||||
$NewGroup = New-Object VMware.Vim.ClusterHostGroup -Property @{
|
||||
'Name'=$Name
|
||||
'Host'=$VMHost.Id
|
||||
}
|
||||
|
||||
$spec = New-Object VMware.Vim.ClusterConfigSpecEx -Property @{
|
||||
'GroupSpec'=(New-Object VMware.Vim.ClusterGroupSpec -Property @{
|
||||
'Info'=$NewGroup
|
||||
})
|
||||
}
|
||||
|
||||
$ClusterToReconfig = Get-View -VIObject $Cluster -Property Name
|
||||
$ClusterToReconfig.ReconfigureComputeResource($spec, $true)
|
||||
43
Scripts/New-ClusterVmGroup.ps1
Normal file
43
Scripts/New-ClusterVmGroup.ps1
Normal file
@@ -0,0 +1,43 @@
|
||||
<#
|
||||
.NOTES
|
||||
===========================================================================
|
||||
Script name: New-ClusterVmGroup.ps1
|
||||
Created on: 2016-10-25
|
||||
Author: Peter D. Jorgensen (@pjorg, pjorg.com)
|
||||
Dependencies: None known
|
||||
===Tested Against Environment====
|
||||
vSphere Version: 5.5, 6.0
|
||||
PowerCLI Version: PowerCLI 6.5R1
|
||||
PowerShell Version: 5.0
|
||||
OS Version: Windows 10, Windows 7
|
||||
===========================================================================
|
||||
.DESCRIPTION
|
||||
Creates a DRS VM Group in a vSphere cluster.
|
||||
.Example
|
||||
$ProdCluster = Get-Cluster *prod*
|
||||
$EvenVMs = $ProdCluster | Get-VM | ?{ $_.Name -match 'MyVM-\d*[02468]+' }
|
||||
.\New-ClusterVmGroup.ps1 -Name 'EvenVMs' -Cluster $ProdCluster -VM $EvenVMs
|
||||
#>
|
||||
[CmdletBinding()]
|
||||
Param(
|
||||
[Parameter(Mandatory=$True,Position=1)]
|
||||
[String]$Name,
|
||||
[Parameter(Mandatory=$True,ValueFromPipeline=$True,Position=2)]
|
||||
[VMware.VimAutomation.ViCore.Types.V1.Inventory.Cluster]$Cluster,
|
||||
[Parameter(Mandatory=$False,Position=3)]
|
||||
[VMware.VimAutomation.ViCore.Types.V1.Inventory.VirtualMachine[]]$VM
|
||||
)
|
||||
|
||||
$NewGroup = New-Object VMware.Vim.ClusterVmGroup -Property @{
|
||||
'Name'=$Name
|
||||
'VM'=$VM.Id
|
||||
}
|
||||
|
||||
$spec = New-Object VMware.Vim.ClusterConfigSpecEx -Property @{
|
||||
'GroupSpec'=(New-Object VMware.Vim.ClusterGroupSpec -Property @{
|
||||
'Info'=$NewGroup
|
||||
})
|
||||
}
|
||||
|
||||
$ClusterToReconfig = Get-View -VIObject $Cluster -Property Name
|
||||
$ClusterToReconfig.ReconfigureComputeResource($spec, $true)
|
||||
48
Scripts/New-ClusterVmHostRule.ps1
Normal file
48
Scripts/New-ClusterVmHostRule.ps1
Normal file
@@ -0,0 +1,48 @@
|
||||
<#
|
||||
.NOTES
|
||||
===========================================================================
|
||||
Script name: New-ClusterVmHostRule.ps1
|
||||
Created on: 2016-10-25
|
||||
Author: Peter D. Jorgensen (@pjorg, pjorg.com)
|
||||
Dependencies: None known
|
||||
===Tested Against Environment====
|
||||
vSphere Version: 5.5, 6.0
|
||||
PowerCLI Version: PowerCLI 6.5R1
|
||||
PowerShell Version: 5.0
|
||||
OS Version: Windows 10, Windows 7
|
||||
===========================================================================
|
||||
.DESCRIPTION
|
||||
Creates a VM to Host affinity rule in a vSphere cluster.
|
||||
.Example
|
||||
$ProdCluster = Get-Cluster *prod*
|
||||
.\New-ClusterVmHostRule.ps1 -Name 'Even VMs to Odd Hosts' -AffineHostGroupName 'OddHosts' -VMGroupName 'EvenVMs' -Enabled:$true -Cluster $ProdCluster
|
||||
#>
|
||||
[CmdletBinding()]
|
||||
Param(
|
||||
[Parameter(Mandatory=$True,Position=1)]
|
||||
[String]$Name,
|
||||
[Parameter(Mandatory=$True,Position=2)]
|
||||
[String]$AffineHostGroupName,
|
||||
[Parameter(Mandatory=$True,Position=3)]
|
||||
[String]$VMGroupName,
|
||||
[Parameter(Mandatory=$False,Position=4)]
|
||||
[Switch]$Enabled=$True,
|
||||
[Parameter(Mandatory=$True,ValueFromPipeline=$True,Position=5)]
|
||||
[VMware.VimAutomation.ViCore.Types.V1.Inventory.Cluster]$Cluster
|
||||
)
|
||||
|
||||
$NewRule = New-Object VMware.Vim.ClusterVmHostRuleInfo -Property @{
|
||||
'AffineHostGroupName'=$AffineHostGroupName
|
||||
'VmGroupName'=$VMGroupName
|
||||
'Enabled'=$Enabled
|
||||
'Name'=$Name
|
||||
}
|
||||
|
||||
$spec = New-Object VMware.Vim.ClusterConfigSpecEx -Property @{
|
||||
'RulesSpec'=(New-Object VMware.Vim.ClusterRuleSpec -Property @{
|
||||
'Info'=$NewRule
|
||||
})
|
||||
}
|
||||
|
||||
$ClusterToReconfig = Get-View -VIObject $Cluster -Property Name
|
||||
$ClusterToReconfig.ReconfigureComputeResource($spec, $true)
|
||||
Reference in New Issue
Block a user