Archive for the ‘Powershell’ Category.

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:

"Name","Email","SMS","IM"
"Marsellus Wallace","marsellus.wallace@opsmode.com","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 (http://technet.microsoft.com/en-us/library/hh205990.aspx) 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. (http://www.microsoft.com/download/en/details.aspx?id=17851)

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 /Server:OPSRMS01.opsmgr.se

image

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

image

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:
Microsoft.EnterpriseManagement.OperationsManager.ClientShell.StartupOPSMGRdev.ps1

image

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

image

Update!
Cory Delamarter have written a post on the same subject but with an other angle.
Check it out here:
http://blogs.technet.com/b/corydelamarter/archive/2011/03/25/using-the-operations-manager-command-shell-against-multiple-management-groups.aspx

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..

$rmsServer=”RMS.fqdn
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:
http://blogs.technet.com/b/stefan_stranger/archive/2010/11/30/what-monitors-rules-and-discoveries-are-running-on-an-opsmgr-agent.aspx

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;

PowerShell: List agent based on setting

Based on the data you get from the cmdlet get-agent you can list all agents with a specific setting.

This line for example, will list all agents with the Agent Proxy setting enabled:
get-agent | where {$_.ProxyingEnabled -like $true}

Change $_.ProxyingEnabled to $_.ManuallyInstalled and you’ll get a list with all manually installed agents.

In OM2007 SP1 there is a bug on updating the ManuallyInstalled property, so that wont work. This is corrected in R2.
If you dont have to use powershell there is a workaround in this thread.

 
Your options are:
PrimaryManagementServerName
Id
LastModified
Name
DisplayName
HostComputer
HostedHealthService
HealthState
PrincipalName
NetworkName
ComputerName
Domain
IPAddress
Version
RequestCompression
CommunicationPort
MaximumSizeOfAllTransferredFilesBytes
MaximumQueueSizeBytes
ManuallyInstalled
InstallTime
InstalledBy
CreateListener
AuthenticationName
ActionAccountIdentity
HeartbeatInterval
ProxyingEnabled
ManagementGroup
ManagementGroupId