<WriteActionModuleType ID="Microsoft.LS.2010.WriteActionModuleType.StartPoolMaintainence" Accessibility="Internal" Batching="false">
<Configuration>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="MaintenanceWindowInMinutes" type="xsd:integer"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="PoolFqdn" type="xsd:string"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="Comment" type="xsd:string"/>
</Configuration>
<OverrideableParameters>
<OverrideableParameter ID="MaintenanceWindowInMinutes" Selector="$Config/MaintenanceWindowInMinutes$" ParameterType="int"/>
<OverrideableParameter ID="Comment" Selector="$Config/Comment$" ParameterType="string"/>
</OverrideableParameters>
<ModuleImplementation Isolation="Any">
<Composite>
<MemberModules>
<WriteAction ID="Microsoft.LS.2010.WriteAction.StartPoolMaintainence" TypeID="Windows!Microsoft.Windows.PowerShellWriteAction">
<ScriptName>StartPoolMaintainence.ps1</ScriptName>
<ScriptBody><Script>
param ([String] $PoolFqdn, [int] $MaintenanceWindowInMinutes, [String] $Comment)
##########################################################################################################
# PARAMETERS:
# NAME TYPE COMMENT
# 1. Pool Fqdn [string]
# 2. MaintenanceWindowInMinutes [int] (Window to put in maintenance mode, it is required only when IsStartMM is set to true)
# 3. Comment [string] (Comment for putting in maintenance mode, it is required only when IsStartMM is set to true)
# ALGORITHM:
# 1. Put pool class into MM.
# 1. Find server roles contained by given pool and process server roles.
# 2. Find pool watcher for given pool and process pool watchers.
# 3. Find port watcher for given pool and process port watchers.
##########################################################################################################
#CONSTANTS################################################################################################
$START_MAINTENANCE_MODE_MESSAGE = "Starting maintenance mode for: {0}"
$OPSMGMT_LOG_KEY = "HKLM:\SOFTWARE\Microsoft\PowerShell\1\PowerShellSnapIns\Microsoft.EnterpriseManagement.OperationsManager.Client"
$INVALID_POOL = "LS Pool {0} does not exists. Please enter valid Pool Fqdn."
$MM_REASON = "PlannedOther"
$PROPERTY_VALUE = "Value of {0} is {1}."
$NO_NULL_POOL = "Pool Fqdn can not be empty"
$DEFAULT_COMMENT = "Pool Maintenance {0}"
$MM_WINDOW_GE_0 = "Maintenance Window In Minutes parameter should be greater than 0"
##########################################################################################################
#HELPER FUNCTIONS#########################################################################################
function StartMaintenanceMode($monitoringObject)
{
write-host -for yellow ($START_MAINTENANCE_MODE_MESSAGE -f $monitoringObject.DisplayName)
$startTime = [DateTime]::Now
$endTime = $startTime.AddMinutes($MaintenanceWindowInMinutes)
New-MaintenanceWindow -startTime:$startTime -endTime:$endTime -reason:$MM_REASON -comment:$Comment -monitoringObject:$monitoringObject
#To confirm your result and the retuned time is Universal Time
Get-MaintenanceWindow -MonitoringObject $monitoringObject
}
##########################################################################################################
if ([string]::IsNullOrEmpty($PoolFqdn))
{
throw $NO_NULL_POOL
}
if ([string]::IsNullOrEmpty($Comment))
{
$Comment = ($DEFAULT_COMMENT -f [DateTime]::Now)
}
if ($MaintenanceWindowInMinutes -le 0)
{
throw $MM_WINDOW_GE_0
}
$CommandShellPath = $null
if (test-path $OPSMGMT_LOG_KEY)
{
$CommandShellPath = (get-item $OPSMGMT_LOG_KEY).GetValue("ApplicationBase")
if(!$CommandShellPath)
{
throw "Can not read operation manager installation path. Verify that entry {0}\ApplicationBase is not empty." -f $OPSMGMT_LOG_KEY
}
}
else
{
throw "Can not read operation manager installation path. Verify that path {0} exists." -f $OPSMGMT_LOG_KEY
}
$PROPERTY_VALUE -f "CommandShell Path", $CommandShellPath
cd "$CommandShellPath"
.\Microsoft.EnterpriseManagement.OperationsManager.ClientShell.Startup.ps1
# 1. Process Lync Pool
$poolClass = Get-MonitoringClass | where-object {$_.Name -LIKE "Microsoft.LS.2010.Cluster" }
$poolClassInstance = get-monitoringobject -MonitoringClass: $poolClass | where { $_."[Microsoft.LS.2010.Cluster].PoolFqdn" -eq $poolFqdn }
if ($poolClassInstance -eq $null)
{
throw $INVALID_POOL -f $PoolFqdn
}
StartMaintenanceMode $poolClassInstance
# 2. Process Lync Server Roles
$serverRoleClass = Get-MonitoringClass | where-object {$_.Name -LIKE "Microsoft.LS.2010.ServerRole" }
$serverRoleInstances = @(get-monitoringobject -MonitoringClass: $serverRoleClass | where { $_."[Microsoft.LS.2010.ServerRole].PoolFqdn" -eq $poolFqdn })
foreach ($serverRoleInstance in $serverRoleInstances)
{
StartMaintenanceMode $serverRoleInstance
}
# 3. Process Lync Server Synthetic Transaction Watchers
$poolWatcherClass = Get-MonitoringClass | where-object {$_.Name -LIKE "Microsoft.LS.2010.ClusterWatcher" }
$poolWatcherInstances = @(get-monitoringobject -MonitoringClass: $poolWatcherClass | where { $_."[Microsoft.LS.2010.ClusterWatcher].ClusterFqdn" -eq $poolFqdn })
foreach ($poolWatcherInstance in $poolWatcherInstances)
{
StartMaintenanceMode $poolWatcherInstance
}