locked
Maintenance Mode Powershell command for patching servers RRS feed

  • Question

  • Hi, I'm trying to find a basic powershell script/comandlet for automatically setting main mode on servers which are being shutdown/rebooted as part of a patching schdule.  I've seen quite a few maint mode scheduling tools but they aren't what I need here.  Our Server patching team use a 3rd party product (Shavlik) which essentially runs its own powershell script that calls a psshutdown exe which actually does the reboot of the server.  What I was hoping was to be able to edit the existing powershell to set the Main mode on the server (the servers/schedules etc are read in as params from basically text files) just prior to the call within the script that executes the psshutdown command.

    What I was thinking was to embed within the existing powershell the snapin for OpsManager commandlets and then set the new  maintenance window ie:

    $starttime = [System.DateTime]::Now

    $endtime = $starttime.AddHours(0.5)

    Add-PSSnapin "Microsoft.EnterpriseManagement.OperationsManager.Client" -ErrorVariable errSnapin;

    New-MaintenanceWindow -starttime $starttime -endtime $endtime -reason PlannedOther -reason "Patches applied"

    Is this all I would need to set Main mode within the existing Powershell script or is there more to it?  I'm not all that familiar with powershell but need to start somewhere I suppose!!

    Cheers... 

     

     

    Wednesday, October 13, 2010 1:12 PM

Answers

  • Depending on your security model, I'm thinking you might have a problem running this...  You would be running this script from a remote server?  The permissions used to run the script would need to have OpsMgr permissions also.

    A possible workaround, your script on the Shavlick server would drop an even in the Windows event log, and the OpsMgr server would pick up that event and enable MM that way...  Check this blog for the last few posts: http://derekhar.blogspot.com

    • Proposed as answer by Nicholas Li Thursday, October 14, 2010 6:46 AM
    • Marked as answer by Nicholas Li Monday, October 18, 2010 2:52 AM
    Wednesday, October 13, 2010 4:46 PM