Update pester and add vrops script
Updated Pester test so it can be called with parameters and included vROPS Maintenance Mode Script
This commit is contained in:
@@ -4,11 +4,15 @@ Created on: 07/15/2016
|
|||||||
Author: Alan Renouf, @alanrenouf
|
Author: Alan Renouf, @alanrenouf
|
||||||
Description: The purpose of this pester test is to ensure the PowerCLI modules are imported and a connection and disconnection can be made to a vCenter
|
Description: The purpose of this pester test is to ensure the PowerCLI modules are imported and a connection and disconnection can be made to a vCenter
|
||||||
Dependencies: Pester Module
|
Dependencies: Pester Module
|
||||||
|
Example run:
|
||||||
|
|
||||||
|
Invoke-Pester -Script @{ Path = '.\Test Connection to VC.ps1'; Parameters = @{ VCNAME="VC01.local"; VCUSER="Administrator@vsphere.local"; VCPASS="Admin!23"} }
|
||||||
|
|
||||||
#>
|
#>
|
||||||
|
|
||||||
$VCNAME = "MyVC@Mydomain.local"
|
$VCUSER = $Parameters.Get_Item("VCUSER")
|
||||||
$VCUSER = "Administrator@vsphere.local"
|
$VCPASS = $Parameters.Get_Item("VCPASS")
|
||||||
$VCPASS = "Admin!23"
|
$VCNAME = $Parameters.Get_Item("VCNAME")
|
||||||
|
|
||||||
Describe "PowerCLI Tests" {
|
Describe "PowerCLI Tests" {
|
||||||
It "Importing PowerCLI Modules" {
|
It "Importing PowerCLI Modules" {
|
||||||
|
|||||||
116
Scripts/vRealize Operations Maintenance Mode.ps1
Normal file
116
Scripts/vRealize Operations Maintenance Mode.ps1
Normal file
@@ -0,0 +1,116 @@
|
|||||||
|
Connect-VIServer vc-l-01a.corp.local -User administrator@vsphere.local -Password VMware1!
|
||||||
|
Connect-OMServer vrops.corp1.local -User admin -Password VMware1!
|
||||||
|
|
||||||
|
function Enable-OMMaintenance {
|
||||||
|
<#
|
||||||
|
.NOTES
|
||||||
|
Script name: vRealize Operations Maintenance Mode.ps1
|
||||||
|
Created on: 07/26/2016
|
||||||
|
Author: Alan Renouf, @alanrenouf
|
||||||
|
Dependencies: PowerCLI 6.0 R2 or later
|
||||||
|
.DESCRIPTION
|
||||||
|
Places a vSphere Inventory object into maintenance mode in vRealize Operations
|
||||||
|
.Example
|
||||||
|
Set All VMs with a name as backup as being in maintenance mode for 20 minutes:
|
||||||
|
|
||||||
|
Get-VM backup* | Enable-OMMaintenance -MaintenanceTime 20
|
||||||
|
|
||||||
|
Name Health ResourceKind Description
|
||||||
|
---- ------ ------------ -----------
|
||||||
|
backup-089e13fd-7d7a-0 Grey VirtualMachine
|
||||||
|
backup-d90e0b39-2618-0 Grey VirtualMachine
|
||||||
|
backup-e48ca842-316a-0 Grey VirtualMachine
|
||||||
|
backup-77da3713-919a-0 Grey VirtualMachine
|
||||||
|
backup-c32f4da8-86c4-0 Grey VirtualMachine
|
||||||
|
backup-c3fcb95c-cfe2-0 Grey VirtualMachine
|
||||||
|
backup-4318bb1e-614a-0 Grey VirtualMachine
|
||||||
|
|
||||||
|
#>
|
||||||
|
[CmdletBinding()]
|
||||||
|
param(
|
||||||
|
[Parameter(Position=0, Mandatory=$true, ValueFromPipeline=$true)]
|
||||||
|
[ValidateNotNullOrEmpty()]
|
||||||
|
[System.String]
|
||||||
|
$Resource,
|
||||||
|
|
||||||
|
[Parameter(Position=1, Mandatory=$true)]
|
||||||
|
[ValidateNotNullOrEmpty()]
|
||||||
|
[Int]
|
||||||
|
$MaintenanceTime
|
||||||
|
)
|
||||||
|
process {
|
||||||
|
Foreach ($Entry in $resource) {
|
||||||
|
$Item = Get-Inventory -Name $Entry | Get-OMResource
|
||||||
|
if (-not $Item) {
|
||||||
|
throw "$Entry not found"
|
||||||
|
} Else {
|
||||||
|
$Item.ExtensionData.MarkResourceAsBeingMaintained($MaintenanceTime)
|
||||||
|
Get-Inventory -Name $Entry | Get-OMResource
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function Disable-OMMaintenance {
|
||||||
|
<#
|
||||||
|
.NOTES
|
||||||
|
Script name: vRealize Operations Maintenance Mode.ps1
|
||||||
|
Created on: 07/26/2016
|
||||||
|
Author: Alan Renouf, @alanrenouf
|
||||||
|
Dependencies: PowerCLI 6.0 R2 or later
|
||||||
|
.DESCRIPTION
|
||||||
|
Removes a vSphere Inventory object from maintenance mode in vRealize Operations
|
||||||
|
.Example
|
||||||
|
Disable maintenance mode for all VMs with a name of backup
|
||||||
|
|
||||||
|
Get-VM backup* | Disable-OMMaintenance
|
||||||
|
|
||||||
|
Name Health ResourceKind Description
|
||||||
|
---- ------ ------------ -----------
|
||||||
|
backup-089e13fd-7d7a-0 Grey VirtualMachine
|
||||||
|
backup-d90e0b39-2618-0 Grey VirtualMachine
|
||||||
|
backup-e48ca842-316a-0 Grey VirtualMachine
|
||||||
|
backup-77da3713-919a-0 Grey VirtualMachine
|
||||||
|
backup-c32f4da8-86c4-0 Yellow VirtualMachine
|
||||||
|
backup-c3fcb95c-cfe2-0 Yellow VirtualMachine
|
||||||
|
backup-4318bb1e-614a-0 Yellow VirtualMachine
|
||||||
|
|
||||||
|
#>
|
||||||
|
[CmdletBinding()]
|
||||||
|
param(
|
||||||
|
[Parameter(Position=0, Mandatory=$true, ValueFromPipeline=$true)]
|
||||||
|
[ValidateNotNullOrEmpty()]
|
||||||
|
[System.String]
|
||||||
|
$Resource
|
||||||
|
)
|
||||||
|
process {
|
||||||
|
Foreach ($Entry in $resource) {
|
||||||
|
$Item = Get-Inventory -Name $Entry | Get-OMResource
|
||||||
|
if (-not $Item) {
|
||||||
|
throw "$Entry not found"
|
||||||
|
} Else {
|
||||||
|
$Item.ExtensionData.UnmarkResourceAsBeingMaintained()
|
||||||
|
Get-Inventory -Name $Entry | Get-OMResource
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Write-Host "Enable a single host as being in maintenance mode for 1 minute"
|
||||||
|
Enable-OMMaintenance -Resource ESX-01a* -MaintenanceTime 1
|
||||||
|
|
||||||
|
Write-Host "List All Host Resources and their state"
|
||||||
|
Get-OMResource ESX-* | Select Name, State | FT
|
||||||
|
|
||||||
|
Write-Host "Set All VMs with a name as backup as being in maintenance mode for 20 minutes"
|
||||||
|
Get-VM backup* | Enable-OMMaintenance -MaintenanceTime 20
|
||||||
|
|
||||||
|
Write-Host "List All Backup VM Resources and their state"
|
||||||
|
Get-VM backup* | Get-OMResource | Select Name, State | FT
|
||||||
|
|
||||||
|
Write-Host "Disable maintenance mode for all VMs with a name as backup as we have completed our scheduled work"
|
||||||
|
Get-VM backup* | Disable-OMMaintenance
|
||||||
|
|
||||||
|
Write-Host "List All VM Resources and their state"
|
||||||
|
Get-VM backup* | Get-OMResource | Select Name, State | FT
|
||||||
|
|
||||||
Reference in New Issue
Block a user