Archive for the ‘Powershell’ Category.

Start Azure Automation runbook from powershell

With the new Azure Automation cmdlets I wrote about in the previous post we are now able to start runbooks from outside of Azure.
Here is an example how to start a runbook and also get the output from the runbook:

$AzureAccount = "Name of Azure Automation Account"
$RBname = "Name of runbook to start"
$Params = @{"Param1" = "Value1";"Param2" = "Value2"}

$RBjob = Start-AzureAutomationRunbook -AutomationAccountName $AzureAccount -name $RBname -Parameters $Params

DO {
    $RBjobId = Get-AzureAutomationJob -AutomationAccountName $AzureAccount -id $RBjob.Id
    $RBjobstatus = $RBjobId.Status
    } Until ($RBjobstatus -eq "Completed")

Get-AzureAutomationJobOutput -AutomationAccountName $AzureAccount -Id $RBjob.Id -stream Any

Azure Automation Powershell cmdlets

With the Azure Tool kit being updated last week we got a couple of cmdlets for Azure Automation, so now we are able to start, stop get jobs and so on from our runbooks in Azure Automation from on-premises.

Here are the new cmdlets:

To download the updated powershell module go here:

For reference on the new cmdlets, go here:

Using Powershell in Orchestrator

Create subscribers from .CSV

Here is a small powershell script for creating multiple subscribers from a CSV-file.

Your file should look like this:

"Marsellus Wallace","","12345678","marsellusw"

And the code looks like this:

$NotificationSubscribers = Import-Csv "D:\temp\SCOMNotificationSubscribers.csv"

foreach($NotificationSubscriber in $NotificationSubscribers)
$Name = $NotificationSubscriber.Name
$eMail = $NotificationSubscriber.Email
$SMS = $NotificationSubscriber.SMS
$IM = $NotificationSubscriber.IM

Add-SCOMNotificationSubscriber -Name $Name -DeviceList $eMail,"sms:$SMS","sip:$IM"

Web Console prerequisites, OpsMgr 2012

When installing the Web Console there is a couple of components that is required, the Operations Manager 2012 Supported Configuration ( list these:

  • Recommended processor speed: 2.8 GHz or faster.
  • Minimum memory: not less than 2 GB.
  • Operating System: Windows Server 2008 R2
  • Processor Architecture: must be AMD64
  • Internet Information Services (IIS) v7.5 or later, with the IIS Management Console and the following role services installed:
    • Static Content
    • Default Document
    • Directory Browsing
    • HTTP Errors
    • HTTP Logging
    • Request Monitor
    • Request Filtering
    • Static Content Compression
    • Web Server (IIS) Support
    • IIS 6 Metabase Compatibility
    • ASP.NET
    • Windows Authentication
  • Default website: must have an http or https binding configured
  • Both .NET Framework 3.5 SP1 and .NET Framework 4 is required for setup to run. For more information, see the following.


The role services is easily installed with powershell, which makes it a little quicker then using Server Manager GUI:

Import-Module ServerManager
Add-WindowsFeature NET-Framework-Core,Web-WebServer,Web-Static-Content,Web-Default-Doc,Web-Dir-Browsing,Web-Http-Errors,Web-Asp-Net,Web-Http-Logging,Web-Request-Monitor,Web-Windows-Auth,Web-Filtering,Web-Stat-Compression,Web-Mgmt-Console,Web-Metabase

As you might see I’ve also added NET-Framework-Core  (.NET Framework 3.5.1) there as well.

When the IIS install is ready you should install .NET Framework 4. (

If you installed .NET Framework 4 before installing the IIS you’ll get an error:

The ASP.NET 4.0 handler is not registered with IIS.
The ASP.NET 4.0 handler is not registered with IIS 

To fix this, the Operations Manager 2012 Deployment document states that you should run:

%WINDIR%\Microsoft.NET\Framework64\v4.0.30319\aspnet_regiis.exe -r

I suggest that that you add the -enable option (%WINDIR%\Microsoft.NET\Framework64\v4.0.30319\aspnet_regiis.exe -enable -r), that enables the ASP.NET ISAPI extension. And gets rid of this prerequisites error:

Web Console cannot operate properly because the ISAPI and CGI Restrictions in Internet Information Services (IIS) are disabled or missing for ASP.NET 4.0.
Web Console cannot operate properly because the ISAPI and CGI Restrictions in Internet Information Services (IIS) are disabled or missing for ASP.NET 4.0.

Lastly do a restart of the server before running the setup again.

Manage multiple Management Groups with PowerShell

Sometimes we have more than one Management Group (MG), production, test and maybe a development environment. When opening the Operations Manager Console it connects with the last MG you were connected to. This is controlled by the registry value SDKServiceMachine in HKEY_CURRENT_USER\Software\Microsoft\Microsoft Operations Manager\3.0\User Settings

If we want to control this, there is a switch when opening console:
Microsoft.MOM.UI.Console.exe /


So for the console we can create different shortcuts for the MG’s with the switch..

When it comes to the Operations Manager Shell there isn’t any switch to do it the “easy way”. I do like this:

First I makes as many copy’s of the file Microsoft.EnterpriseManagement.OperationsManager.ClientShell.Startup.ps1 as I have Management Groups. Renaming them to the different MG names, for example:
Microsoft.EnterpriseManagement.OperationsManager.ClientShell.StartupOPSMGRdev.ps1 for my development environment.

Second I open the ..StartupOPSMGRdev.ps1-file in my preferred editor and change line 10


Just adding your RMS fqdn (remove : “”)

Third I make a copy of the Operations Manager Shell shortcut for every MG and change the .Startup.ps1 to the name you gave the Startup file, in my case it will be:


So now I have a shortcut for every Management Group in my environment.


Cory Delamarter have written a post on the same subject but with an other angle.
Check it out here:

Putting Unix/Linux servers in MM with Powershell

I saw a question in the TechNet forum today on how to schedule Maintenance mode for Unix/Linux servers.
After some testing this powershell script came out, put it in the task scheduler to automate it, or even better put it in the Opalis policy that is taking care of your maintenance..

add-pssnapin “Microsoft.EnterpriseManagement.OperationsManager.Client”;
Set-Location “OperationsManagerMonitoring::”;
$mgConnection = New-ManagementGroupConnection -connectionString:$rmsServer;

Set-Location $rmsServer;

$unixClass = get-monitoringclass -name "Microsoft.Unix.Computer"
$monObject = Get-MonitoringObject -monitoringclass:$unixClass
$mmServer = $monObject | where {$_.displayname -eq "unixserver.fqdn"}

New-MaintenanceWindow -MonitoringObject $mmServer -Comment "Enter maintenance mode reason here" -StartTime (Get-Date) -EndTime (Get-Date).AddMinutes(60)

Whats running on the agent…?

Ever wanted to now what rules, monitors and discoveries is running on the OpsMgr agent? I sure did..

Now the answer is a great Powershell script written by Stefan Stranger.

It is to be found here:

Server still monitored after a discovery has been disabled

I see this question a lot in the technet forums:

“I don’t want to monitor the IIS on this server and have disabled the discovery, but the server wont disappear. How do I get rid of it?”

To resolve this you just need to open a Operations Manager Shell and enter: Remove-DisabledMonitoringObject

Description of cmdlet:
Removes all monitoring objects for which discovery is disabled. For example, if you created an override to disable discovery for a particular database on a database server, calling this cmdlet would cause the removal of this database from Operations Manager.

Scheduling OpsMgr PowerShell scripts

When scheduling an Operations Manager PowerShell script you have to load the powershell snapins.

Insert this in the beginning of your script

$ServerName = “hostname”
add-pssnapin “Microsoft.EnterpriseManagement.OperationsManager.Client”;
set-location “OperationsManagerMonitoring::”;
new-managementGroupConnection -ConnectionString:$ServerName;
set-location $ServerName;