penguinisland offical blog
Wednesday, 8 August 2012
test
#######################################################################################################################
# Puts a OM2012 Computer Group in Maintenance Mode using PowerShell
# Author: Stefan Stranger (Microsoft)
# Example usage: Run Get-Help Get-SCOMMaintenanceModeForGroups.ps1 -Examples
# Disclamer: This program source code is provided "AS IS" without warranty representation or condition of any kind
# either express or implied, including but not limited to conditions or other terms of merchantability and/or
# fitness for a particular purpose. The user assumes the entire risk as to the accuracy and the use of this
# program code.
# Tested on PowerShell v3 and OM2012 environment
# Date: 03-07-2012
# Name: Get-SCOMMaintenanceModeForGroups.ps1
# v1.000 - 03-07-2012 - Stefan Stranger - initial sstranger's release
# v1.001 - 06-07-2012 - Stefan Stranger - Added Eventlog and WhatIf Switch
########################################################################################################################
<#
.SYNOPSIS
Places all members of a SCOM Computer Group in into maintenance mode, and creates new active maintenance mode entries.
.DESCRIPTION
The Start-MaintenanceModeForGroups script places all members of a SCOM Computer Group into maintenance mode, and creates new active maintenance mode entries.
When in maintenance mode, alerts, notifications, rules, monitors, automatic responses, state changes, and new alerts are suppressed for the class instance.
.EXAMPLE
Start-SCOMMaintenanceModeForGroup.ps1 -ComputerGroup "All Windows Computers" -EndTime 10 -Reason "UnplannedOther" -Comment "Testing Maintenance Mode" -Verbose
Puts all Members of the "All Windows Computer" Group in Maintenance Mode for 10 minutes, with Reason "UnplannedOther" and with Comment "Testing Maintenance Mode".
Adding Verbose information.
.EXAMPLE
Start-SCOMMaintenanceModeForGroup.ps1 -ComputerGroup "All Windows Computers" -EndTime 10 -Reason "UnplannedOther" -Comment "Testing Maintenance Mode" -Eventlog
Puts all Members of the "All Windows Computer" Group in Maintenance Mode for 10 minutes, with Reason "UnplannedOther" and with Comment "Testing Maintenance Mode".
Writing Eventlog information to the "Operations Manager" Eventlog (eventid 998 and eventid 999). Can be used for tracking and debugging when Task Scheduler is being used.
.EXAMPLE
Start-SCOMMaintenanceModeForGroup.ps1 -ComputerGroup "All Windows Computers" -EndTime 10 -Reason "UnplannedOther" -Comment "Testing Maintenance Mode" -WhatIf
Using the WhatIf switch shows which Members of the "All Windows Computer" Group would be put in Maintenance Mode if you had run the script. So the members are not really
put into maintenance mode. For testing purposes.
.PARAMETER ComputerGroup
The SCOM Computer Group name for which members you want to put in Maintenance Mode.
.PARAMETER EndTime
Specifies the time the maintenance will end. The minimum amount of time a resource can be in maintenance mode is 5 minutes.
.PARAMETER Reason
Specifies the reason for placing the resource into maintenance mode. Valid values are:
UnplannedOther, PlannedHardwareMaintenance, UnplannedHardwareMaintenance, PlannedHardwareInstallation,
UnplannedHardwareInstallation, PlannedOperatingSystemReconfiguration, UnplannedOperatingSystemReconfiguration,
PlannedApplicationMaintenance, ApplicationInstallation, ApplicationUnresponsive, ApplicationUnstable,
SecurityIssue, LossOfNetworkConnectivity
.Parameter Comment
Allows you to type a comment about the maintenance activity.
.Parameter EventLog
Writes information to the "Operations Manager" Eventlog to track what is happening.
.Link
http://blogs.technet.com/stefan_stranger#>
#requires -version 2.0
[CmdletBinding(SupportsShouldProcess=$true)]
param
(
[Parameter(Mandatory=$True,
ValueFromPipeline=$True,
ValueFromPipelineByPropertyName=$True,
HelpMessage='What is the ComputerGroup you want to put in Maintenance Mode?')]
[Alias("Group")]
[string[]]$ComputerGroup,
[Parameter(Mandatory=$True,
ValueFromPipeline=$false,
ValueFromPipelineByPropertyName=$True,
HelpMessage='Specifies the time the maintenance will end. The minimum amount of time a resource can be in
maintenance mode is 5 minutes. This is a required parameter')]
[int]$EndTime,
[Parameter(Mandatory=$False,
ValueFromPipeline=$True,
ValueFromPipelineByPropertyName=$True,
HelpMessage='UnplannedOther, PlannedHardwareMaintenance, UnplannedHardwareMaintenance,
PlannedHardwareInstallation, UnplannedHardwareInstallation, PlannedOperatingSystemReconfiguration,
UnplannedOperatingSystemReconfiguration, PlannedApplicationMaintenance, ApplicationInstallation,
ApplicationUnresponsive, ApplicationUnstable, SecurityIssue, LossOfNetworkConnectivity')]
[string]$Reason,
[Parameter(Mandatory=$False,
ValueFromPipeline=$True,
ValueFromPipelineByPropertyName=$True,
HelpMessage='Allows you to type a comment about the maintenance activity.')]
[string]$Comment,
[switch]$EventLog
)
set-strictmode -version latest
$start=Get-Date
$currentlog = $start.ToString()
Write-Verbose "Starting $($myinvocation.mycommand)"
Write-Verbose "Ready to put ComputerGroup $ComputerGroup in Maintenance Mode"
Function Start-SCOMMaintenanceModeForGroup
{
<#
.SYNOPSIS
Sets a SCOM Group in Maintenance Mode
.DESCRIPTION
Sets the members of a SCOM Group in Maintenance Mode
.EXAMPLE
Start-SCOMMaintenanceModeForGroup -ComputerGroup "All Windows Computers" -EndTime 10 -Reason "UnplannedOther" -Comment "Testing Maintenance Mode" -Verbose
.PARAMETER ComputerGroup
The SCOM Computer Group name for which members you want to put in Maintenance Mode.
.PARAMETER EndTime
Specifies the time the maintenance will end. The minimum amount of time a resource can be in maintenance mode is 5 minutes.
.PARAMETER Reason
Specifies the reason for placing the resource into maintenance mode. Valid values are:
UnplannedOther, PlannedHardwareMaintenance, UnplannedHardwareMaintenance, PlannedHardwareInstallation,
UnplannedHardwareInstallation, PlannedOperatingSystemReconfiguration, UnplannedOperatingSystemReconfiguration,
PlannedApplicationMaintenance, ApplicationInstallation, ApplicationUnresponsive, ApplicationUnstable,
SecurityIssue, LossOfNetworkConnectivity
.Parameter Comment
Allows you to type a comment about the maintenance activity.
.Link
http://blogs.technet.com/stefan_stranger
#>
[CmdletBinding(SupportsShouldProcess=$true)]
param
(
[Parameter(Mandatory=$True,
ValueFromPipeline=$True,
ValueFromPipelineByPropertyName=$True,
HelpMessage='What is the ComputerGroup you want to put in Maintenance Mode?')]
[Alias("Group")]
[string[]]$ComputerGroup,
[Parameter(Mandatory=$True,
ValueFromPipeline=$false,
ValueFromPipelineByPropertyName=$True,
HelpMessage='Specifies the time the maintenance will end. The minimum amount of time a resource can be in
maintenance mode is 5 minutes. This is a required parameter')]
[int]$EndTime,
[Parameter(Mandatory=$False,
ValueFromPipeline=$True,
ValueFromPipelineByPropertyName=$True,
HelpMessage='UnplannedOther, PlannedHardwareMaintenance, UnplannedHardwareMaintenance,
PlannedHardwareInstallation, UnplannedHardwareInstallation, PlannedOperatingSystemReconfiguration,
UnplannedOperatingSystemReconfiguration, PlannedApplicationMaintenance, ApplicationInstallation,
ApplicationUnresponsive, ApplicationUnstable, SecurityIssue, LossOfNetworkConnectivity')]
[string]$Reason,
[Parameter(Mandatory=$False,
ValueFromPipeline=$True,
ValueFromPipelineByPropertyName=$True,
HelpMessage='Allows you to type a comment about the maintenance activity.')]
[string]$Comment,
[switch]$EventLog
)
Begin
{
Write-Verbose "Starting Function Start-SCOMMaintenanceModeForGroup Function"
#Check for minumum Maintenance mode period of 5 mins.
if($endtime -lt 5)
{
Write-Error "The time span for the maintenance mode should be at least 5 minutes." -ErrorAction Stop
}
Write-Verbose "Following Group Members will be put in Maintenance Mode:"
$ComputerGroupMembers = Get-SCOMMonitoringObject -DisplayName $ComputerGroup
if($ComputerGroupMembers)
{
$ComputerGroupMemberNames = $ComputerGroupMembers.getrelatedMonitoringObjects().DisplayName
Write-Verbose "$ComputerGroupMemberNames"
#Retrieve Management Servers so we can check if we don't put Management Servers in MM.
$MSs = Get-SCOMManagementServer
}
else
{
Write-Error "No Members of ComputerGroup $ComputerGroup found" -ErrorAction Stop
}
} #End Begin
Process
{
#Put Agents in Maintenance Mode
foreach ($agent in $ComputerGroupMembers.getrelatedMonitoringObjects())
{
Write-Verbose "Checking if ComputerGroup Member $agent is not a Management Server"
if(($MSs | Select DisplayName).displayname -eq $agent)
{
Write-Verbose "We don't want to put a Management Server in MM. Skipping"
}
else
{
Write-Verbose "Let's put Agent $Agent in Maintenance Mode"
$Instance = Get-SCOMClassInstance -Name $Agent
if ($PSCmdlet.ShouldProcess("Putting $Agent in Maintenande Mode for $($Endtime) minutes") )
{
#Added 5 seconds to EndTime to prevent failing the Start-SCOMMaintenanceMode cmdlet. Min. 5 mins is needed.
Start-SCOMMaintenanceMode -Instance $Instance -EndTime ([System.DateTime]::Now).AddSeconds(5).addMinutes($EndTime) -Reason $Reason -Comment $Comment
}#End of whatif
}#End of else
}#End Foreach
if ($PSBoundParameters['EventLog'])
{
write-eventlog -LogName "Operations Manager" -Source "OpsMgr SDK Service" -EventID 999 -message "The following Objects are put into in Maintenance Mode for $($EndTime) minutes: $($ComputerGroupMembers.getrelatedMonitoringObjects())"
}#End if
} #End Process
End
{
Write-Verbose "Finished Function Start-SCOMMaintenanceModeForGroup Function"
}
}
#Main
try
{
if ($PSBoundParameters['EventLog'])
{
write-eventlog -LogName "Operations Manager" -Source "OpsMgr SDK Service" -EventID 998 -message "The $($myinvocation.mycommand) is used to put Objects in Maintenance Mode"
}
Write-Verbose "Checking if OperationsManager Module is loaded"
#Check if OperationsManager Module is loaded.
if(!(Get-Module OperationsManager))
{
Write-Verbose "Importing OperationsManager Module"
Import-Module OperationsManager -ErrorAction Stop
}
Write-Verbose "Checking for OM2012 environment"
#Check if OM2012 is being used.
if(!(Get-Module OperationsManager).Description -eq "Operations Manager OperationsManagerV10 Module")
{
Write-Error "This script is only for OM2012"
}
#Call Function
if ($PSBoundParameters['EventLog'])
{
Start-SCOMMaintenanceModeForGroup -ComputerGroup $ComputerGroup -EndTime $EndTime -Reason $Reason -Comment $Comment -EventLog
}
else
{
Start-SCOMMaintenanceModeForGroup -ComputerGroup $ComputerGroup -EndTime $EndTime -Reason $Reason -Comment $Comment
}
} #End Try
catch [System.IO.FileNotFoundException]
{
"OperationsManager Module not found"
$_.Exception.Message
}
catch
{
Write-Warning "Oops something went wrong"
$_.Exception.Message
}
$end=Get-Date
Write-Debug ("Total processing time {0}" -f ($end-$start).ToString())
Write-Verbose "Ending $($myinvocation.mycommand)"
Wednesday, 6 June 2012
I have plans for penguin island THIS SUMMER!!!
Hey Penguin Island fans We still hope your looking forward to our CPPPS opening on June 16th and 2 Days later for TEAM COZZA VS TEAM CPSpongebob. Anyways Next Month is July and thats officaly the Summer Hoildays and this summer hoilday I Have Plans my plans are bellow
Plans will be told soon... Watch this space Later on when it gets UPDATED!
What do think of these it is unknow that I will do these plans but stay tuned if i do
Waddle On
Monday, 4 June 2012
Team COZZA VS Team CPSpongebob Sneeky Peek
Hey Penguin island fans as you may know when Our Game Officially Opens the Team COZZA VS Team CPSpongebob will start 2 days later (18th June) Ive Made a SECRET ROOM (A Shop) here's a sneaky peek
I Have heard Rumors that there will be EXCLUSIVE Items there in that SECRET SHOP so if I was you I would get them when the Party starts I mean when there GONE there GONE!
What do you think of this SECRET ROOM (Shop) Where do you think this SECRET ROOM (Shop) Be Leave your comments bellow and tell us what you think Remember to vote for next party beside you --->
Waddle On
I Have heard Rumors that there will be EXCLUSIVE Items there in that SECRET SHOP so if I was you I would get them when the Party starts I mean when there GONE there GONE!
What do you think of this SECRET ROOM (Shop) Where do you think this SECRET ROOM (Shop) Be Leave your comments bellow and tell us what you think Remember to vote for next party beside you --->
Waddle On
Welcome
Hey Penguin Island Fans Welcome to Penguin Island the place for fun and partys our 1st Party (Team COZZA VS Team CPSpongebob) is gonna come about 2 days after the game is open after that party well.,.... we don't know what to pick so COZZA put up Poll asking which party you like to see next e.g Puffle Party Anyways continuing with the 1st party Ive Heard Rumors that they will be a SECRET AREA with EXCLUSIVE can't say much more yet until then
Waddle On
Waddle On
Subscribe to:
Posts (Atom)
