System Center Operations Manager Invalid Management Group Removal

Invalid Management Group Removal

We recently carried out some work for a client who had a completely ruined installation of System Center Operations Manager (SCOM).

Who had done what to it, we may never know, but it was clear that the only fix was to start again. This was not such a bad thing as they did want to change the name of their Management Group anyway – which secretly lead us to believe that someone had been messing and trying to carry this out, hence the mess of the installation!

We went ahead and carried out a completely new installation of Operations Manager as this is what they wanted, however, if you are an administrator of Operations Manager, you will probably know about the potential for an absolute nightmare here – the old Management Group and the new Management Group now being referenced on the servers and end users machines (although in this case, they only wanted servers being monitored by Operations Manager).

We managed to resolve this issue by using a PowerShell script. We did not write this PowerShell script ourselves and we apologise now for not giving the credit where it is due, but we cannot remember where we got it from – if it’s you, let us know and we will update with credit.

The plan is very simple, go into the Operations Manager server, check for error EventID 20046 in the Event Viewer (which will give you the name of a server trying to report with an invalid Management Group) then edit and run the PowerShell script to remove the reportedly invalid Management Group from that server.

PowerShell Script to Remove SCOM Invalid Management Group

The PowerShell script we used is below, note these variables that you must enter per server:

  • $ComputerName = The server name with the invalid management group
  • $ManagementGroup = The name of the invalid management group
param(
$ComputerName = "SERVERNAME",
$ManagementGroup = "MGMT GROUP NAME"
)

Function Remove-SCOMManagementGroup ($ComputerName)
{
$sb = {
param($ManagementGroup,
$ComputerName)
Try {
$OMCfg = New-Object -ComObject AgentConfigManager.MgmtSvcCfg
} catch {
throw "$ComputerName doesn't have the SCOM 2012 agent installed"
}
$mgs = $OMCfg.GetManagementGroups() | %{$_.managementGroupName}
if ($mgs -contains $ManagementGroup) {
$OMCfg.RemoveManagementGroup($ManagementGroup)
return "$ManagementGroup removed from $ComputerName"
} else {
return "$ComputerName does not report to $ManagementGroup"
}
}
Invoke-Command -ScriptBlock $sb -ComputerName $ComputerName -ArgumentList @($ManagementGroup,$ComputerName)
}
Remove-SCOMManagementGroup -ManagementGroup $ManagementGroup -ComputerName $ComputerName

Once the PowerShell script has completed, you either need to restart the Microsoft Monitoring Agent service (Service Name is: HealthService) on the affected machine or reboot it.

If you then go into your server Control Panel and then into the Microsoft Monitoring Agent applet, you should now see that you only have the corrent new Management Group on there and that the invalid old one has been removed.

System Center Orchestrator

Of course, if you know how to use System Center Orchestrator and you have it installed in your environment, you can setup a new Runbook to check for EventID 20046 and then trigger the PowerShell script from there.

Feedback

If you have any questions or feedback on this guide, we would love to hear from you. You can contact us via our Social Media channels or just leave us a message below in the comments box.

SCORCH runbooks not showing in SCCM or SCSM

system center

When you create a new System Center Orchestrator Runbook and you have checked it in ready to use, you may not see it in systems that will want to use it, like Configuration Manager, Microsoft Deployment Toolkit or Service Manager.

This is due to authorisation cache not updating and as so, not showing the newly created runbook.

Guide

To fix this, you will need to open up Microsoft SQL Management Console and run the following SQL query on your Orchestrator database:

Truncate Table [Microsoft.SystemCenter.Orchestrator.Internal].AuthorizationCache
EXEC [Microsoft.SystemCenter.Orchestrator.Maintenance].EnqueueRecurrentTask ‘ClearAuthorizationCache’

Once you have run this, you should then head back to where you want to use the runbook and you should now be able to see it!

Remember if you are using something like Service Manager, you will need to run the connector synchronisation again after running the SQL query on the database.

Comments

If you have any questions or feedback on this post, please feel free to leave us a message below in the comments section.

Bulk Remove SCOM Management Packs

system center

If you are using System Center Operations Manager (SCOM) then you may have Management Packs in your system that you may longer want – especially if, like me, you go and add as many as you can in blissful ignorance expecting to get lots of tasty data. Then realising that this is a terrible idea and you now have loads of Management Packs and their dependencies to delete manually!

Using PowerShell to Bulk Remove SCOM Management Packs

Open up the Operations Manager Shell:

Bulk Remove SCOM Management Packs 1

This will connect to your Operations Manager Management Server and allow you to run commands against it.

Copy the code below and make the amendments you require:

where:

Get-SCOMManagementPack | where {$_.DisplayName -like "*SQL*"}  | Remove-SCOMManagementPack
  • “*SQL*” – The wildcard of a Management Pack you want to remove.

Hit enter and it will start the process of removing the Management Packs that you have stated in the wildcard. If you do not want to use the wildcard, just remove the *’s and enter the full and correct Management Pack name.

This process can take some time to complete depending on how many you are trying to remove, so it may look like the process is doing nothing – but it is, just be patient with it.

Once this is complete, you can go into your Operations Manager Console and then browse to your Management Packs and you should notice that they have now been removed.

Feedback

If you have any comments or questions on this guide, please feel free to leave us a message below and we will get back to you as soon as we can.

Operations Manager – Enable agent proxy on all agents

scom 2012

If you are using System Center Operations Manager (SCOM) then you may want to enable agent proxy on all your agents. If you want to do this then you can use the power of Powershell to carry this out.

Just open up a Powershell command box and use the following command:

get-SCOMagent | where {$_.ProxyingEnabled -match "False"} | Enable-SCOMAgentProxy

If you want to ensure that any future machines have their agent proxy enabled, then you can run this Powershell command:

add-pssnapin "Microsoft.EnterpriseManagement.OperationsManager.Client";
new-managementGroupConnection -ConnectionString:scomserver.domain.com;
set-location "OperationsManagerMonitoring::";
Set-DefaultSetting -Name HealthServiceProxyingEnabled -Value True

Now when any new machines are added into your environment, you will see that the proxy agent is already enabled on them.

COMMENTS

If you have any questions or feedback on this guide, please feel free to leave us a message below.

Bulk Delete Multiple Operations Manager Management Packs [2020 Updated]

microsoft windows white logo

If you are using System Center Operations Manager and you want to bulk remove multiple Management Packs, then you can use the power of the Operations Manager Shell to carry it out.

First of all, you need to open up the Operations Manager Shell. Then you should run the following command:

Get-SCOMManagementPack | where Name -like "*Microsoft.SQLServer*"

where:

  • “*Microsoft.SQLServer*” = the management pack names that you want to remove. Note that you can use a * wildcard here.

This will list all the management packs that you have installed as per the criteria you have entered and should look something like this:

Operations Manager Powershell Output
Operations Manager Powershell Output

Check you are happy with this list and then move onto the following command which will remove all of those management packs listed:

Get-SCOMManagementPack | where Name -like "*Microsoft.SQLServer*" | Remove-SCManagementPack

This will then go through and remove all of the management packs that match your criteria.

Depending on how many you are trying to remove at the same time – this could take a while.

This has been updated and tested on System Center Operations Manager 2019.

Feedback

If you have any questions or feedback on this guide, please feel free to leave us a message below and we will get back to you as soon as we can.

System Center Orchestrator – SQL Query to show log file data

SystemCenter logo

If you are using System Center Orchestrator (SCORCH)  Runbooks then you may have run into issues where the database is increasing in size due to the large amount of log files being created. This typically occurs when monitoring event logs on servers amongst some other runbook options in SCORCH.

If you want to check how many log files are in existence per each individual runbook that you have, then you can run the following SQL query on your SCORCH database.

SQL Query

SELECT COUNT(OBJECTS.Name) AS Instances,
POLICIES.Name AS Runbook, 
Objects.Name 
FROM OBJECTINSTANCEDATA
INNER JOIN OBJECTINSTANCES ON OBJECTINSTANCEDATA.ObjectInstanceID = OBJECTINSTANCES.UniqueID
INNER JOIN OBJECTS ON OBJECTINSTANCES.ObjectID = OBJECTS.UniqueID
INNER JOIN POLICIES ON OBJECTS.ParentID = POLICIES.UniqueID
GROUP BY Policies.Name,
Objects.Name
ORDER BY Instances DESC

Running this will bring back a list of your existing runbooks and the total amount of logs against each one. You can then purge logs manually or re-evaluate your automated log purge settings within the Runbook Designer Console.

More Queries

Our full range of SQL and WQL Collection queries are available here.

Feedback

If you have any questions or feedback about this post, or if you would like us to create any queries for you, please go ahead and leave us a message below in the comments section and we will get back to you as quick as we can.

System Center Operations Manager – Apply Licence using PowerShell

ssc 0

If you are using System Center Operations Manager (SCOM) then you will find that you will need to apply your correct licence key to take it from an evaluation version up to a full version.

To make this a simple process, you can run the following PowerShell command on your Operations Manager server:

#Import Module
import-module operationsmanager

#Set License Key
New-SCOMManagementGroupConnection
Set-SCOMLicense -ProductId "YOUR LICENCE KEY"

#Restart Services
Stop-Service OmSdk,HealthService,CsHost
sleep -Milliseconds 10000
Start-Service CsHost,HealthService,OmSdk
sleep -Milliseconds 10000

#Show Current License Status
Get-SCOMManagementGroup | ft skuforlicense, version, timeofexpiration –a

It is best to open PowerShell ISE (ensure you elevate and run as admin) and this should then look like the below. Ensure that you enter your own Product ID licence key.

System Center Operations Manager - Apply Licence using PowerShell 2

Click on the Green go button and this will then import the operations manager module to begin with then it will create a connection to your Management Group, it will then apply your licence key. You will get a message pop up asking you to approve the change:

System Center Operations Manager - Apply Licence using PowerShell 3

Click Yes to continue.

It will then restart the required services and once complete, the final step will show you the licence status of your server.

System Center Operations Manager - Apply Licence using PowerShell 4

Note that if it is still showing as “Eval” you should reboot the server and manually run the final command. This should then show as being correct.

COMMENTS

If you have any questions or feedback on this guide, please feel free to leave us a comment below and we will get back to you as soon as we can.

 

System Center Operations Manager – Pre-Requisites Powershell Script

ssc 0

If you are installing System Center Operations Manager, there are a number of pre-requisites that you need to install before running the installer.

To make the pre-requisites installation easier, you can run the below Powershell command which will download and install all of the pre-reqs for you.

Import-Module ServerManager
Add-WindowsFeature NET-Framework-Core,AS-HTTP-Activation,Web-Static-Content,Web-Default-Doc,Web-Dir-Browsing,Web-Http-Errors,Web-Http-Logging,Web-Request-Monitor,Web-Filtering,Web-Stat-Compression,AS-Web-Support,Web-Metabase,Web-Asp-Net,Web-Windows-Auth –restart

##This section will download the Report Viewer and System CLR Types for SQL Server 2012 for Windows Server 2012R2 to folder called C:\SCOM\2012R2\Prereqs. Once files has been downloaded it will automatically install

$dwnld = ‘C:\SCOM\2012R2\Prereqs’
if (!(Test-Path -path $dwnld))
{
New-Item $dwnld -type directory
}
$object = New-Object Net.WebClient
$RPTurl = ‘https://download.microsoft.com/download/F/B/7/FB728406-A1EE-4AB5-9C56-74EB8BDDF2FF/ReportViewer.msi’
$object.DownloadFile($RPTurl, “$dwnldReportViewer.msi”)

$RPTurl = ‘https://go.microsoft.com/fwlink/?LinkID=239644&clcid=0x409’
$object.DownloadFile($RPTurl, “$dwnldSQLSysClrTypes.msi”)

Start-Process -FilePath “$dwnldSQLSysClrTypes.msi” -ArgumentList ‘/q’ -Wait
Start-Process -FilePath “$dwnldReportViewer.msi” -ArgumentList ‘/q’ -Wait

Thanks to Mai Ali for this script.

Comments

If you have any questions or feedback on this guide, please feel free to post us a message below and we will reply as soon as we can.