Merge pull request #409 from ashishsharma-git/patch-1
Update vRealize Operations Maintenance Mode.ps1
This commit is contained in:
@@ -10,6 +10,10 @@ function Enable-OMMaintenance {
|
||||
.Example
|
||||
Set All VMs with a name as backup as being in maintenance mode for 20 minutes:
|
||||
|
||||
Since Get-Inventory does not return Datastore Objects, we need to specify we're passing Datastore objects using switch "IsDatastore"
|
||||
|
||||
Get-Datastore DS1 | Enable-OMMaintenance -MaintenanceTime 20 -IsDatastore True
|
||||
|
||||
Get-VM backup* | Enable-OMMaintenance -MaintenanceTime 20
|
||||
|
||||
Name Health ResourceKind Description
|
||||
@@ -33,10 +37,28 @@ function Enable-OMMaintenance {
|
||||
[Parameter(Position=1, Mandatory=$true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[Int]
|
||||
$MaintenanceTime
|
||||
$MaintenanceTime,
|
||||
|
||||
[Parameter(Position=2, Mandatory=$false)]
|
||||
[ValidateSet(“True”, “False”)]
|
||||
[System.String]
|
||||
$IsDatastore= $false
|
||||
|
||||
)
|
||||
process {
|
||||
Foreach ($Entry in $resource) {
|
||||
if ($IsDatastore -eq $true)
|
||||
{
|
||||
$Item = Get-Datastore -Name $Entry | Get-OMResource
|
||||
if (-not $Item) {
|
||||
throw "$Entry not found"
|
||||
} Else {
|
||||
$Item.ExtensionData.MarkResourceAsBeingMaintained($MaintenanceTime)
|
||||
Get-Datastore -Name $Entry | Get-OMResource
|
||||
}
|
||||
}
|
||||
Else
|
||||
{
|
||||
$Item = Get-Inventory -Name $Entry | Get-OMResource
|
||||
if (-not $Item) {
|
||||
throw "$Entry not found"
|
||||
@@ -47,6 +69,7 @@ function Enable-OMMaintenance {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function Disable-OMMaintenance {
|
||||
<#
|
||||
@@ -60,6 +83,10 @@ function Disable-OMMaintenance {
|
||||
.Example
|
||||
Disable maintenance mode for all VMs with a name of backup
|
||||
|
||||
Since Get-Inventory does not return Datastore Objects, we need to specify we're passing Datastore objects using switch "IsDatastore"
|
||||
|
||||
Get-Datastore DS1 | Disable-OMMaintenance -IsDatastore True
|
||||
|
||||
Get-VM backup* | Disable-OMMaintenance
|
||||
|
||||
Name Health ResourceKind Description
|
||||
@@ -78,10 +105,27 @@ function Disable-OMMaintenance {
|
||||
[Parameter(Position=0, Mandatory=$true, ValueFromPipeline=$true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[System.String]
|
||||
$Resource
|
||||
$Resource,
|
||||
|
||||
[Parameter(Position=1, Mandatory=$false)]
|
||||
[ValidateSet(“True”, “False”)]
|
||||
[System.String]
|
||||
$IsDatastore= $false
|
||||
)
|
||||
process {
|
||||
Foreach ($Entry in $resource) {
|
||||
If ($IsDatastore -eq $true)
|
||||
{
|
||||
$Item = Get-Datastore -Name $Entry | Get-OMResource
|
||||
if (-not $Item) {
|
||||
throw "$Entry not found"
|
||||
} Else {
|
||||
$Item.ExtensionData.UnmarkResourceAsBeingMaintained()
|
||||
Get-Datastore -Name $Entry | Get-OMResource
|
||||
}
|
||||
}
|
||||
Else
|
||||
{
|
||||
$Item = Get-Inventory -Name $Entry | Get-OMResource
|
||||
if (-not $Item) {
|
||||
throw "$Entry not found"
|
||||
@@ -92,6 +136,7 @@ function Disable-OMMaintenance {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#Write-Host "Enable a single host as being in maintenance mode for 1 minute"
|
||||
#Enable-OMMaintenance -Resource ESX-01a* -MaintenanceTime 1
|
||||
|
||||
Reference in New Issue
Block a user