Maintenance mode via Powershell

Hello!

I am not usually working with SCOM but found something i wanted to create now during summer when it's a bit of spare time here at work.
My goal is to create a script (powershell) that i can put on desktop of each domain member in domain that will put the server in maintenancemode when run.

I thought this to be fairly easy but i run in to trouble quite fast with my script, from what i have gathered i need to fin out what SCOMclassInstance a server is part of before i can put it in maintenancemode so i used the following script.

$FQDN = "$env:computername."+"$env:userdnsdomain"
$Instance=Get-SCOMClassInstance-Name$FQDN 

But i get a error when doing so
Get-SCOMClassInstance : The Data Access service is either not running or not yet initialized.

I have confirmed that the Data access service is running and tried to restart it without any progress. Anyoine have a idea ?

Kind Regards
Lee

  

July 13th, 2015 9:04am

Hi Lee,

Your monitored computers do not run the data access service, only your SCOM management servers run that service.  The monitored computers have the Microsoft Monitoring Agent, which is different.

You would need to run your PowerShell code against a management server, so you would be better off having your computers that need to go into maintenance mode defined on the management server, like in a file.  You would then be able to use PowerShell to go through the computers putting each one in maintenance mode.

David

Free Windows Admin Tool Kit Click here and download it now
July 13th, 2015 11:10am

Another option might be to leverage Orchestrator and a self-service type methodology. I'm not sure that you would want just "anyone" to arbitrarily be able to put an object into Maintenance Mode. 

Therefore, if you use a self-service trigger (via Service Manager), you could also include an approval process around it first. 

July 13th, 2015 1:25pm

Hi,

You need to target your management server using -computername in the command :

$Instance= Get-SCOMClassInstance -computername $yourserverSCOM -Name $ServerName 

Free Windows Admin Tool Kit Click here and download it now
July 13th, 2015 1:56pm

One option I have used in the past is to create an executable which takes a couple of parameters:

- duration

- reason

Put this on the server desktop (using SCCM). Any user can run this executable (they don't need SCOM rights) and when they do, the executable takes the parameters and creates an event in the application event log.

A simple rule looks for the event id and source eventcreate and this triggers a script (command channel) that puts the server into maintenance mode.

It is a little convoluted but the aim was to allow engineers who had no rights within SCOM to put a server they were working on into maintenance mode.

Regards

Graham 

July 13th, 2015 5:22pm

Hi,

You need to target your management server using -computername in the command :

$Instance= Get-SCOMClassInstance -computername $yourserverSCOM -Name $ServerName 

  • Marked as answer by Lee Armano 22 hours 33 minutes ago
Free Windows Admin Tool Kit Click here and download it now
July 13th, 2015 5:52pm

Hi,

You need to target your management server using -computername in the command :

$Instance= Get-SCOMClassInstance -computername $yourserverSCOM -Name $ServerName 

  • Marked as answer by Lee Armano Tuesday, July 28, 2015 8:38 AM
July 13th, 2015 5:52pm

make sure that Data Access service is up and running on the connected management server. You can check the management server, you powershell connected to, by running the powershell cmdlet Get-SCOMManagementGroupConnection. Make sure that the managementserverName is correct and isactive is ture.
If not, you can create a new Management Group Connection by running New-SCOMManagementGroupConnection ComputerName MyServer.
for detail, pls. refer to

http://blogs.technet.com/b/corydelamarter/archive/2013/02/08/opsmgr-2012-powershell-getting-connected.aspx
Roger

Free Windows Admin Tool Kit Click here and download it now
July 14th, 2015 2:30am

Hi and thanks for all the answers.

The goal here was to put a .ps1 file on the desktop of each server so that engineers could put that specific server in maintenance mode when working with it, since all of them doesn't have access to SCOM.

I have tried the sugestion

$Instance= Get-SCOMClassInstance -computername $yourserverSCOM -Name $ServerName 

But it's not working either, running the command retorns no data.

Import-ModuleOperationsManager
$FQDN="$env:computername."+"$env:userdnsdomain"

$Instance=Get-SCOMClassInstance-ComputerName$ScomServer-Name$FQDN
# Ask user for number of minutes

$Minutes = 30

$Time=((Get-Date).AddMinutes($Minutes))

Start-SCOMMaintenanceMode

-Instance$Instance-EndTime$Time-ReasonOther(Unplanned)-CommentBackup of Domaincontrollers

Above is the script i have been working with but with no luck :(

/Lee

July 15th, 2015 3:14am

Hi,

Import-Module OperationsManager

$Instance= Get-SCOMClassInstance -computername $yourserverSCOM -Name $ServerName 

It works in my environment.

What is the error when you run this command ? :

Get-SCOMClassInstance -computername $yourserverSCOM -Name $ServerName 

Free Windows Admin Tool Kit Click here and download it now
July 15th, 2015 4:06am

Hi.

I made a mistake when writing the script, i get correct information now.
Going to see if i can get it to work now.

/Lee

July 15th, 2015 6:44am

Hi and thanks for all the answers.

The goal here was to put a .ps1 file on the desktop of each server so that engineers could put that specific server in maintenance mode when working with it, since all of them doesn't have access to SCOM.

I have tried the sugestion

$Instance= Get-SCOMClassInstance -computername $yourserverSCOM -Name $ServerName 

But it's not working either, running the command retorns no data.

Import-ModuleOperationsManager
$FQDN="$env:computername."+"$env:userdnsdomain"

$Instance=Get-SCOMClassInstance-ComputerName$ScomServer-Name$FQDN
# Ask user for number of minutes

$Minutes = 30

$Time=((Get-Date).AddMinutes($Minutes))

Start-SCOMMaintenanceMode

-Instance$Instance-EndTime$Time-ReasonOther(Unplanned)-CommentBackup of Domaincontrollers

Above is the script i have been working with but with no luck :(

/Lee

Free Windows Admin Tool Kit Click here and download it now
July 15th, 2015 7:13am

Hi and thanks for all the answers.

The goal here was to put a .ps1 file on the desktop of each server so that engineers could put that specific server in maintenance mode when working with it, since all of them doesn't have access to SCOM.

I have tried the sugestion

$Instance= Get-SCOMClassInstance -computername $yourserverSCOM -Name $ServerName 

But it's not working either, running the command retorns no data.

Import-ModuleOperationsManager
$FQDN="$env:computername."+"$env:userdnsdomain"

$Instance=Get-SCOMClassInstance-ComputerName$ScomServer-Name$FQDN
# Ask user for number of minutes

$Minutes = 30

$Time=((Get-Date).AddMinutes($Minutes))

Start-SCOMMaintenanceMode

-Instance$Instance-EndTime$Time-ReasonOther(Unplanned)-CommentBackup of Domaincontrollers

Above is the script i have been working with but with no luck :(

/Lee

July 15th, 2015 7:13am

Hi,

Import-Module OperationsManager

$Instance= Get-SCOMClassInstance -computername $yourserverSCOM -Name $ServerName 

It works in my environment.

What is the error when you run this command ? :

Get-SCOMClassInstance -computername $yourserverSCOM -Name $ServerName 

Free Windows Admin Tool Kit Click here and download it now
July 15th, 2015 8:06am

Hi,

Import-Module OperationsManager

$Instance= Get-SCOMClassInstance -computername $yourserverSCOM -Name $ServerName 

It works in my environment.

What is the error when you run this command ? :

Get-SCOMClassInstance -computername $yourserverSCOM -Name $ServerName 

July 15th, 2015 8:06am

Hi,

Import-Module OperationsManager

$Instance= Get-SCOMClassInstance -computername $yourserverSCOM -Name $ServerName 

It works in my environment.

What is the error when you run this command ? :

Get-SCOMClassInstance -computername $yourserverSCOM -Name $ServerName 

  • Proposed as answer by Julien DECORMON Monday, July 27, 2015 9:31 PM
  • Marked as answer by Lee Armano Tuesday, July 28, 2015 8:38 AM
Free Windows Admin Tool Kit Click here and download it now
July 15th, 2015 8:06am

Hi.

I made a mistake when writing the script, i get correct information now.
Going to see if i can get it to work now.

/Lee

July 15th, 2015 10:43am

Hi.

I made a mistake when writing the script, i get correct information now.
Going to see if i can get it to work now.

/Lee

Free Windows Admin Tool Kit Click here and download it now
July 15th, 2015 10:43am

Hi Sir,

Is there any update ?

Best Regards,

Elton Ji

July 27th, 2015 11:01am

Hi,

Sorry for not closing this, above information helped me to solve my problem.
We do now have a .ps1 script on the desktop of each server in our domin that the engineers can use to put the server in to 30 min maintenancemode if needed.

Thanks for the help!

/Lee

Free Windows Admin Tool Kit Click here and download it now
July 28th, 2015 4:44am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics