| <ManagementPack ContentReadable="true" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <Manifest> <Identity> <ID>MaintenanceModeSample</ID> <Version>1.0.0.18</Version> </Identity> <Name>MaintenanceMode.Sample</Name> <References> <Reference Alias="SCDW"> <ID>Microsoft.SystemCenter.DataWarehouse.Library</ID> <Version>6.1.7043.0</Version> <PublicKeyToken>31bf3856ad364e35</PublicKeyToken> </Reference> <Reference Alias="SystemCenter"> <ID>Microsoft.SystemCenter.Library</ID> <Version>6.1.7043.0</Version> <PublicKeyToken>31bf3856ad364e35</PublicKeyToken> </Reference> <Reference Alias="VMM"> <ID>Microsoft.SystemCenter.VirtualMachineManager.2008.R2</ID> <Version>2.0.4056.0</Version> <PublicKeyToken>31bf3856ad364e35</PublicKeyToken> </Reference> <Reference Alias="WL"> <ID>Microsoft.Windows.Library</ID> <Version>6.1.7043.0</Version> <PublicKeyToken>31bf3856ad364e35</PublicKeyToken> </Reference> <Reference Alias="SL"> <ID>System.Library</ID> <Version>6.1.7043.0</Version> <PublicKeyToken>31bf3856ad364e35</PublicKeyToken> </Reference> </References> </Manifest> <TypeDefinitions> <ModuleTypes> <!-- Start maintenance mode write action for PowerShell script --> <WriteActionModuleType ID="MaintenanceMode.StartAction" Accessibility="Internal" Batching="false"> <Configuration> <xsd:element minOccurs="1" name="TaskId" type="xsd:string" /> </Configuration> <OverrideableParameters> <OverrideableParameter ID="EventData" Selector="$Config/TaskId$" ParameterType="string" /> </OverrideableParameters> <ModuleImplementation Isolation="Any"> <Composite> <MemberModules> <WriteAction ID="StartAction" TypeID="SL!System.CommandExecuter"> <ApplicationName> <![CDATA[%SystemRoot%\system32\windowspowershell\v1.0\powershell.exe]]> </ApplicationName> <WorkingDirectory /> <CommandLine><![CDATA["& '$file/StartMMScript.ps1$' '$Config/TaskId$'"]]></CommandLine> <TimeoutSeconds>120</TimeoutSeconds> <RequireOutput>false</RequireOutput> <Files> <File> <Name>StartMMScript.ps1</Name> <Contents> <![CDATA[ Param($TaskId); #Add the VMM and OM Snapins Add-PSSnapin Microsoft.SystemCenter.VirtualMachineManager Add-PSSnapin Microsoft.EnterpriseManagement.OperationsManager.Client #connect to the VMM server $VMMS = Get-VMMServer localhost if( $Error.Count -ne 0) { eventcreate /T Error /ID 101 /L APPLICATION /SO VMM-MP /D "Failed to put host into maintenance mode: " + $Error[0] return; } #Get the OpsMgr Server Name $MSName = $VMMS.OpsMgrServer #establish console session with OM & 'C:\Program Files\System Center Operations Manager 2007\Microsoft.EnterpriseManagement.OperationsManager.ClientShell.Functions.ps1' Start-OperationsManagerClientShell -ManagementServerName: $MSName -PersistConnection: $true -Interactive: $false; if( $Error.Count -ne 0) { eventcreate /T Error /ID 101 /L APPLICATION /SO VMM-MP /D "Failed to put host into maintenance mode: " + $Error[0] return; } #Get the VMM Job that put the host into maintenance mode $TriggerJob = Get-Job -Id $TaskId #Get the VMM Host Object $MMHost = Get-VMHost -Id $TriggerJob.TargetObjectID #Get the OM computer object $ComputerClass = Get-MonitoringClass -Name 'System.Computer' $ComputerObject = Get-MonitoringObject -MonitoringClass $ComputerClass -Path "\" | Where {$_.PathName -eq $MMHost.Name} #Put the OM computer into Maintenance Mode $time = [DateTime]::Now New-MaintenanceWindow -MonitoringObject $ComputerObject -Comment "Putting into maintenance mode because VMM is in Maintenance Mode" -StartTime $time -EndTime $time.AddYears(99) eventcreate /T Information /ID 100 /L APPLICATION /SO VMM-MP /D 'Host computer is now in maintenance mode' ]]> </Contents> </File> </Files> </WriteAction> </MemberModules> <Composition> <Node ID="StartAction" /> </Composition> </Composite> </ModuleImplementation> <OutputType>SL!System.CommandOutput</OutputType> <InputType>SL!System.BaseData</InputType> </WriteActionModuleType> <!-- Stop maintenance mode write action for PowerShell script --> <WriteActionModuleType ID="MaintenanceMode.StopAction" Accessibility="Internal" Batching="false"> <Configuration> <xsd:element minOccurs="1" name="TaskId" type="xsd:string" /> </Configuration> <OverrideableParameters> <OverrideableParameter ID="EventData" Selector="$Config/TaskId$" ParameterType="string" /> </OverrideableParameters> <ModuleImplementation Isolation="Any"> <Composite> <MemberModules> <WriteAction ID="StartAction" TypeID="SL!System.CommandExecuter"> <ApplicationName> <![CDATA[%SystemRoot%\system32\windowspowershell\v1.0\powershell.exe]]> </ApplicationName> <WorkingDirectory /> <CommandLine><![CDATA["& '$file/StopMMScript.ps1$' '$Config/TaskId$'"]]></CommandLine> <TimeoutSeconds>120</TimeoutSeconds> <RequireOutput>false</RequireOutput> <Files> <File> <Name>StopMMScript.ps1</Name> <Contents> <![CDATA[ Param($TaskId); #Add the VMM and OM Snapins Add-PSSnapin Microsoft.SystemCenter.VirtualMachineManager Add-PSSnapin Microsoft.EnterpriseManagement.OperationsManager.Client #connect to the VMM server $VMMS = Get-VMMServer localhost if( $Error.Count -ne 0) { eventcreate /T Error /ID 101 /L APPLICATION /SO VMM-MP "Failed to remove host computer from maintenance mode: " + $Error[0] } #Get the OpsMgr Server Name $MSName = $VMMS.OpsMgrServer #establish console session with OM & 'C:\Program Files\System Center Operations Manager 2007\Microsoft.EnterpriseManagement.OperationsManager.ClientShell.Functions.ps1' Start-OperationsManagerClientShell -ManagementServerName: $MSName -PersistConnection: $true -Interactive: $false; #Get the VMM Job that put the host into maintenance mode $TriggerJob = Get-Job -Id $TaskId #Get the VMM Host Object $MMHost = Get-VMHost -Id $TriggerJob.TargetObjectID #Get the OM computer object $ComputerClass = Get-MonitoringClass -Name 'System.Computer' $ComputerObject = Get-MonitoringObject -MonitoringClass $ComputerClass -Path "\" | Where {$_.PathName -eq $MMHost.Name} #Remove the OM computer From Maintenance Mode $time = [DateTime]::Now Set-MaintenanceWindow -MonitoringObject $ComputerObject -Comment "Removing from maintenance mode because VMM is out of Maintenance Mode" -EndTime $time eventcreate /T Information /ID 100 /L APPLICATION /SO VMM-MP /D 'Removed Host From Maintenance Mode' ]]> </Contents> </File> </Files> </WriteAction> </MemberModules> <Composition> <Node ID="StartAction" /> </Composition> </Composite> </ModuleImplementation> <OutputType>SL!System.CommandOutput</OutputType> <InputType>SL!System.BaseData</InputType> </WriteActionModuleType> </ModuleTypes> </TypeDefinitions> <Monitoring> <Rules> <!-- Stop Maintenance Mode Rule--> <Rule ID="MaintenanceMode.Sample.StopMM.Rule" Enabled="true" Target="VMM!Microsoft.SystemCenter.VirtualMachineManager.2008.Engine" ConfirmDelivery="true" Remotable="true" Priority="Normal" DiscardLevel="100"> <Category>Custom</Category> <DataSources> <DataSource ID="DS" TypeID="WL!Microsoft.Windows.EventCollector"> <ComputerName>$Target/Host/Property[Type="WL!Microsoft.Windows.Computer"]/NetworkName$</ComputerName> <LogName>VM Manager</LogName> <AllowProxying>false</AllowProxying> <Expression> <And> <Expression> <SimpleExpression> <ValueExpression> <XPathQuery Type="UnsignedInteger">EventDisplayNumber</XPathQuery> </ValueExpression> <Operator>Equal</Operator> <ValueExpression> <Value Type="UnsignedInteger">1705</Value> </ValueExpression> </SimpleExpression> </Expression> <Expression> <SimpleExpression> <ValueExpression> <XPathQuery Type="String">PublisherName</XPathQuery> </ValueExpression> <Operator>Equal</Operator> <ValueExpression> <Value Type="String">Virtual Machine Manager</Value> </ValueExpression> </SimpleExpression> </Expression> <Expression> <SimpleExpression> <ValueExpression> <XPathQuery Type="String">Params/Param[3]</XPathQuery> </ValueExpression> <Operator>Equal</Operator> <ValueExpression> <Value Type="String">Stop maintenance mode</Value> </ValueExpression> </SimpleExpression> </Expression> </And> </Expression> </DataSource> </DataSources> <WriteActions> <WriteAction ID="WriteToDB" TypeID="SystemCenter!Microsoft.SystemCenter.CollectEvent" /> <WriteAction ID="WriteToDW" TypeID="SCDW!Microsoft.SystemCenter.DataWarehouse.PublishEventData" /> <WriteAction ID="MaintenanceMode.Sample.RunStopMM" TypeID="MaintenanceMode.StopAction"> <TaskId>$Data/Params/Param[2]$</TaskId> </WriteAction> </WriteActions> </Rule> <!-- Start Maintenance Mode Rule--> <Rule ID="MaintenanceMode.Sample.StartMM.Rule" Enabled="true" Target="VMM!Microsoft.SystemCenter.VirtualMachineManager.2008.Engine" ConfirmDelivery="true" Remotable="true" Priority="Normal" DiscardLevel="100"> <Category>Custom</Category> <DataSources> <DataSource ID="DS" TypeID="WL!Microsoft.Windows.EventCollector"> <ComputerName>$Target/Host/Property[Type="WL!Microsoft.Windows.Computer"]/NetworkName$</ComputerName> <LogName>VM Manager</LogName> <AllowProxying>false</AllowProxying> <Expression> <And> <Expression> <SimpleExpression> <ValueExpression> <XPathQuery Type="UnsignedInteger">EventDisplayNumber</XPathQuery> </ValueExpression> <Operator>Equal</Operator> <ValueExpression> <Value Type="UnsignedInteger">1704</Value> </ValueExpression> </SimpleExpression> </Expression> <Expression> <SimpleExpression> <ValueExpression> <XPathQuery Type="String">PublisherName</XPathQuery> </ValueExpression> <Operator>Equal</Operator> <ValueExpression> <Value Type="String">Virtual Machine Manager</Value> </ValueExpression> </SimpleExpression> </Expression> <Expression> <SimpleExpression> <ValueExpression> <XPathQuery Type="String">Params/Param[3]</XPathQuery> </ValueExpression> <Operator>Equal</Operator> <ValueExpression> <Value Type="String">Refresh host</Value> </ValueExpression> </SimpleExpression> </Expression> </And> </Expression> </DataSource> </DataSources> <WriteActions> <WriteAction ID="WriteToDB" TypeID="SystemCenter!Microsoft.SystemCenter.CollectEvent" /> <WriteAction ID="WriteToDW" TypeID="SCDW!Microsoft.SystemCenter.DataWarehouse.PublishEventData" /> <WriteAction ID="MaintenanceMode.Sample.RunStartMM" TypeID="MaintenanceMode.StartAction"> <TaskId>$Data/Params/Param[2]$</TaskId> </WriteAction> </WriteActions> </Rule> </Rules> </Monitoring> <LanguagePacks> <LanguagePack ID="ENU" IsDefault="false"> <DisplayStrings> <DisplayString ElementID="MaintenanceMode.StartAction"> <Name>Start Host Maintenance Mode Action</Name> <Description /> </DisplayString> <DisplayString ElementID="MaintenanceModeSample"> <Name>Maintenance Mode Sample MP</Name> </DisplayString> <DisplayString ElementID="MaintenanceMode.Sample.StopMM.Rule"> <Name>Stop Maintenance Mode Rule</Name> </DisplayString> <DisplayString ElementID="MaintenanceMode.Sample.StartMM.Rule"> <Name>Start Maintenance Mode Rule</Name> </DisplayString> </DisplayStrings> </LanguagePack> </LanguagePacks> </ManagementPack> |