LS Start Pool Maintenance task Data source module.

Microsoft.LS.2010.WriteActionModuleType.StartPoolMaintainence (WriteActionModuleType)

Element properties:

TypeWriteActionModuleType
IsolationAny
AccessibilityInternal
RunAsDefault
InputTypeSystem.BaseData

Member Modules:

ID Module Type TypeId RunAs 
Microsoft.LS.2010.WriteAction.StartPoolMaintainence WriteAction Microsoft.Windows.PowerShellWriteAction Default

Overrideable Parameters:

IDParameterTypeSelectorDisplay NameDescription
MaintenanceWindowInMinutesint$Config/MaintenanceWindowInMinutes$Maintenance Window in MinutesMaintenance Window in Minutes
Commentstring$Config/Comment$CommentComment

Source Code:

<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
}

# 4. Process Lync Server Port Watchers
$portWatcherClass = Get-MonitoringClass | where-object {$_.Name -LIKE "Microsoft.LS.2010.PortWatcher" }
$portWatcherInstances = @(get-monitoringobject -MonitoringClass: $portWatcherClass | where { $_."[Microsoft.LS.2010.PortWatcher].ServerName" -eq $poolFqdn })
foreach ($portWatcherInstance in $portWatcherInstances)
{
StartMaintenanceMode $portWatcherInstance
}
</Script></ScriptBody>
<SnapIns>
<SnapIn>Microsoft.EnterpriseManagement.OperationsManager.Client</SnapIn>
</SnapIns>
<Parameters>
<Parameter>
<Name>PoolFqdn</Name>
<Value>$Config/PoolFqdn$</Value>
</Parameter>
<Parameter>
<Name>MaintenanceWindowInMinutes</Name>
<Value>$Config/MaintenanceWindowInMinutes$</Value>
</Parameter>
<Parameter>
<Name>Comment</Name>
<Value>$Config/Comment$</Value>
</Parameter>
</Parameters>
<TimeoutSeconds>120</TimeoutSeconds>
</WriteAction>
</MemberModules>
<Composition>
<Node ID="Microsoft.LS.2010.WriteAction.StartPoolMaintainence"/>
</Composition>
</Composite>
</ModuleImplementation>
<InputType>System!System.BaseData</InputType>
</WriteActionModuleType>