Tuesday 12 August 2008

Updated Agent Maintenance Mode

---Update---

Updated version of this MP at http://derekhar.blogspot.com/2009/11/new-agent-maintenance-mode.html


---------


There is a new version of my Maintenance Mode MP and scripts that can do maintenance mode from the Agent with no extras installed (The original post is here). The 4 files are available for download from http://cid-397bb61b75cc76c5.skydrive.live.com/browse.aspx/Public/AgentMaintModeV2?view=details

-----------

EDIT

Be aware the PowerShell execution policy might block the script from being run.

You may need to do the following:
1. Open the Command Shell, and do "set-executionpolicy remotesigned" (using "allsigned" may be considered a bit more secure.
2. Right-click on the .ps1 files, chose properties and click "Unblock" especially if you've downloaded these scripts using Internet Explorer.

Thanks to Marco for catching this. I had a few people contact with with the earlier version not working and I could never figure out why. Could be the same reason.

----------------

This version adds the ability to turn off maintenance mode from the agent as well as turn it on. The vbscript has been updated with some more options and some instructions on how to use it.

To install or update you need to import the management pack and copy the 2 ps1 files to System Center Operations Manager 2007 program folder on the RMS.

Then you need to copy the vbscript file to any agent managed server and run it to set any server in maintenance mode for the desired time period.

------------------------------

VBScript Usage:

Usage: MaintMode ON|OFF [ON Duration][D][H][M]

Examples: MaintMode ON 6H
MaintMode ON 2D

ON is a mandatory keyword to put a server in maintenance mode.

ON Duration is number of [D]ays [M]inutes or [H]ours Maintenance
Mode should remain ON.

If not specified, the default is 6 hours.
This means Maintenance mode will turn itself OFF after 6 hours.

If ON Duration is specified without [D][H][M], the number is
interpreted as hours.

------------------------------

This MP creates a new class which contains all Windows Operating Systems. There are 2 rules in this class. One listens for the Maint Mode ON event and the other listens for the Maint Mode OFF event. The script on the RMS that turns on Maintenance Mode actually turns it on for all the components of the server and then turns it off again only for the Maint Mode class. This means that even in Maint Mode it can listen for the OFF event.

NOTE: The discovery for this class runs every 12 hours so be aware that systems may take this long after install for the scripts to work

Thanks again to Boris for his examples and scripts for doing maintenance mode.

15 comments:

marco.shaw said...

Now, be aware the PowerShell execution policy might block the script from being run.

You may need to do the following:
1. Open the Command Shell, and do "set-executionpolicy remotesigned" (using "allsigned" may be considered a bit more secure.
2. Right-click on the .ps1 files, and click "Unblock" especially if you've downloaded these scripts using Internet Explorer.

Derek Harkin said...

Thanks Marco, I will add this to the post. Forgot about the whole Alternate Data Stream thing.

Anonymous said...

Hi Derek,

Thank you your updated MP and other scripts. Yes I finally got this working on my test lab. Thanks to Marco for pointing out about the unblock option. That did the trick for me.

Couple things I found:
1. When I put any server on the MM it is off by 5 minutes. For example: If I put a agent on the MM for 60 minutes through the VB script it is only showing 55 minutes on the console. Is that by design since it has to read the event from the application log or is there something you have to fix on the script?

2. I ran the MM off script with MaintMode OFF and it is writing the event to the application log on the agent but nothing is happening on the console.

Thank you again.

Santosh

marco.shaw said...

Santosh,

As for question #1, yes the script does have a extra line to removes 5 minutes from your time. Either edit the PowerShell script to remove this line:
$endtime = $endtime.AddMinutes("-5")
-or-
Add 5 minutes when you enter your total.

I'm not sure about the reasoning behind this though.

I would test #2, but I'm having issues with the VMs that I have access to.

Derek Harkin said...

I usually found that there was a 1 to 2 minute delay in the system actually going in to Maintenance Mode in a small enviroemnt.

If this is not the case in your environment you can simply remove or comment a line in the MaintModeON.ps1 file

$endtime = $endtime.AddMinutes("-5")

or change it to what is suitale in your environment.

In the OFF script there is a debug line that you can uncomment to try and get more information.

# $computername | out-file c:\maintmodeoffdebug.txt -append

just remove the # on this line and each time you run the OFF command it should create a text file at c:\maintmodeoffdebug.txt. This will tell you if the script is actaully being run

Anonymous said...

Hi Derek

Cool trick with the AgentMaintMode_Class! There's a little problem with the MaintModeON.ps1 script. On line 40 the class name doesn't match with the xml.
Also the powershell scripts do not work for computers that are not members of a domain (they do not normally have a domain extension).

It did work after I changed the $computerCriteria to this:

$computerCriteria = "NetbiosComputerName LIKE '" + $computerName + "'"

Derek Harkin said...

Raphael,

Thanks for the catching the typo in the ON script. I have fixed that now.
This was likely the cause of Santosh's issue with the OFF not working.

I dont really like the idea of matching a just by the host name of the computer. Too much of a chance in a large enviroemnt that you may ahve this query reuturing several names.

The right fix for this I think would be to update the VB script to write in the FQDN to the event message and then pass that to the script. I think I will put this in the next version

Anonymous said...

Hi

This script is working great for us. We are trying to get this script to work with Altiris. I made couple changes but I am kind of stuck now. We would like to add this script so that user have option to pick 30, 60, 120 or 240 minutes when picking up the maintenance mode. We don't want user to specify any values except pick up from one of these 4. Please help.
Thank you.

marco.shaw said...

Anonymous,

About the request for 30, 60, 120 or 240 minute intervals only, you want the VBScript to have this limitation right?

I *might* be able to have something by Friday afternoon.

Email me: marco DOT shaw AT gmail DOT com

Derek Harkin said...

Have a look at http://cid-397bb61b75cc76c5.skydrive.live.com/self.aspx/Public/CustomMaintMode/MaintMode-Intervals.vbs

This should be close to what you are looking for. It has the limitation on the intervals available.

Nathan Cook said...

Hi Derek,

Great idea. I have been reviewing your code and I have a question about MaintON.ps1

The code in MaintON is trying to parse the number of seconds from the event log description added by the vbscript however at line 9, you grab the earlier number? I did some testing and i couldn't get it to work without changing line 9

So $length = $ed[$ed.Count-3] should really be:

$length = $ed[$ed.Count-1]

Everything works great after that but from everyones comments, they seem to be working fine with your code as is.

Anonymous said...

Does this work on a clutered 64-bit RMS? I have this working flawlessly on a 32-bit standalone RMS, but on our 64-bit clustered RMS it never puts the computer, agent, etc in maint mode. I can see from the debug file that the script is running, but nothing ever is put in maint mode. Thanks for your efforts.

Anonymous said...

Reply to my anonymous comment above: we have solved the problem. Apparently the mgmt server action account needs to be in the Operations Manager Admins role and it wasn't on this 64-bit clustered rms. Now that it is a member of that role, the MP works perfectly. Thanks again!

Unknown said...

We have been utilizing this in our production environment for a while. Has anyone tried using this in an r2 w/ Server 2008 64 bit?

Matthew

Jorgen said...

I've implemented this just yesterday. RMS is R2 on Win2008 64bit SP2.
The clients ( Win2003 Citrix server ) enter maintence mode just fine but as soon as maintenance mode exits, it starts again! As if the MP rereads the event generated by the vbs script.
Haven't tried it on other clients yet.