update
This commit is contained in:
+76
@@ -0,0 +1,76 @@
|
||||
<#
|
||||
.SYNOPSIS
|
||||
A short one-line action-based description, e.g. 'Tests if a function is valid'
|
||||
.DESCRIPTION
|
||||
A longer description of the function, its purpose, common use cases, etc.
|
||||
.NOTES
|
||||
Information or caveats about the function e.g. 'This function is not supported in Linux'
|
||||
.LINK
|
||||
Specify a URI to a help page, this will show when Get-Help -Online is used.
|
||||
.EXAMPLE
|
||||
Test-MyTestFunction -Verbose
|
||||
Explanation of the function or its result. You can include multiple examples with additional .EXAMPLE lines
|
||||
#>
|
||||
|
||||
function Set-ITDVMwareHostMaintenance {
|
||||
[CmdletBinding()]
|
||||
param (
|
||||
[Parameter(ParameterSetName = 'Enclosure', Mandatory = $true)]
|
||||
[string]
|
||||
$EnclosureName,
|
||||
|
||||
[Parameter(ParameterSetName = 'Manual', Mandatory = $true)]
|
||||
[string[]]
|
||||
$VMHostName,
|
||||
|
||||
[ValidateSet('Maintenance', 'Online', 'Connected')]
|
||||
[string]
|
||||
$State
|
||||
)
|
||||
|
||||
begin {
|
||||
|
||||
}
|
||||
|
||||
process {
|
||||
|
||||
switch ($PSCmdlet.ParameterSetName) {
|
||||
'Enclosure' {
|
||||
Write-Verbose "Setting all VMHosts in enclosure $EnclosureName to $State mode."
|
||||
try {
|
||||
$VMHostName = (Get-OVServer | Where-Object Name -like $EnclosureName -ErrorAction Stop).ServerName
|
||||
}
|
||||
catch {
|
||||
Write-Error "Failed to retrieve enclosure $EnclosureName. Error: $_"
|
||||
throw
|
||||
}
|
||||
}
|
||||
'Manual' {
|
||||
Write-Verbose "Setting specified VMHosts to $State mode."
|
||||
}
|
||||
}
|
||||
|
||||
switch ($State) {
|
||||
'Maintenance' {
|
||||
Write-Verbose "Setting VMHost $VMHostName to Maintenance mode."
|
||||
try {
|
||||
Get-VMHost -Name $VMHostName | Set-VMHost -State Maintenance -Confirm:$false -RunAsync
|
||||
Disable-ITDVMwareVMHostFeature -Name $VMHostName -AlarmActions
|
||||
}
|
||||
catch {
|
||||
Write-Error "Failed to set VMHost $VMHostName to Maintenance mode. Error: $_"
|
||||
throw
|
||||
}
|
||||
}
|
||||
'Online' {
|
||||
Write-Verbose "Setting VMHost $VMHostName to Online mode."
|
||||
Get-VMHost -Name $VMHostName | Set-VMHost -State Connected -Confirm:$false -RunAsync
|
||||
Enable-ITDVMwareVMHostFeature -Name $VMHostName -AlarmActions
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
end {
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user