Archive for SCOM – Script

SCOM 2012 R2 – Export Management Pack every Day

I will today try to explain what you need to export all management pack every day.  It can be usefull if like to take backup, or just like have all version of the management packs.

Read more

Restart Grey SCOM Agent – Opsmgr 2007 R2

First you need to get a list of Agent. Here you can use the Powershell to get the displayname. Now you have the list. You can create a very simpel bat file, one for stop service and one for start service.

Read more

Blog from Cameron Fuller – Debugging the Script or Executable Failed to Run Alert

Over the last couple of years, I have a lot of time to troubleshoot why scripts have failed.

Today I saw Cameron Fuller blog abut this issue. Below you can find a link to his blog.

Link: BlastFromThePast: Debugging the Script or Executable Failed to Run Alert

 

Read more

SCOM alert notification subscription delay sending for x minutes and don’t sent if alert is auto-resolved within that time

In my company we are using SCOM for monitoring our server environment.
Off hours we also get notified about critical alerts using a SMS/GSM modem.
Using default SCOM functionality we delay the sending of notifications by 5 minutes. This works fine for alerts with a “new” state.
However if an alert is closed within the 5 minute period a “closed” notification is sent out.
We do not want to see the closed alerts if an alert auto-resolved within the 5 minute time period. But if a new alert that has aged 5 minutes and sent to our GSM, we definately want to see that closed alert if it auto/manual resolves into the closed state (to make sure someone actually did something about the alert)

Read more

Orphaned Agents

Please run the following query to list all orphaned Agents, please verify if this contains the Agents.

NOTE: This not a support solution from Microsoft

 

— Check for orphaned health services (e.g. agent).

declare @DiscoverySourceId uniqueidentifier;

set @DiscoverySourceId = dbo.fn_DiscoverySourceId_User();

 

SELECT TME.[TypedManagedEntityid], HS.PrincipalName

FROM MTV_HealthService HS

INNER JOIN dbo.[BaseManagedEntity] BHS with(nolock)

ON BHS.[BaseManagedEntityId] = HS.[BaseManagedEntityId]

— get host managed computer instances

INNER JOIN dbo.[TypedManagedEntity] TME with(nolock)

ON TME.[BaseManagedEntityId] = BHS.[TopLevelHostEntityId]

AND TME.[IsDeleted] = 0

INNER JOIN dbo.[DerivedManagedTypes] DMT with(nolock)

ON DMT.[DerivedTypeId] = TME.[ManagedTypeId]

INNER JOIN dbo.[ManagedType] BT with(nolock)

ON DMT.[BaseTypeId] = BT.[ManagedTypeId]

AND BT.[TypeName] = N’Microsoft.Windows.Computer’

— only with missing primary

LEFT OUTER JOIN dbo.Relationship HSC with(nolock)

ON HSC.[SourceEntityId] = HS.[BaseManagedEntityId]

AND HSC.[RelationshipTypeId] = dbo.fn_RelationshipTypeId_HealthServiceCommunication()

AND HSC.[IsDeleted] = 0

INNER JOIN DiscoverySourceToTypedManagedEntity DSTME with(nolock)

ON DSTME.[TypedManagedEntityId] = TME.[TypedManagedEntityId]

AND DSTME.[DiscoverySourceId] = @DiscoverySourceId

WHERE HS.[IsAgent] = 1

AND HSC.[RelationshipId] IS NULL;

 

 

Then please follow these steps which will bring these Agents back to Pending Management, from here please approve the Agents.

 

1. Backup the OperationsManager database

2. Run the below SQL queries to remove the orphaned agents.

 

— DELETE!!! all orphaned agents.

declare @TypedManagedEntityId uniqueidentifier;

declare @DiscoverySourceId uniqueidentifier;

declare @LastErr int;

declare @TimeGenerated datetime;

 

set @TimeGenerated = GETUTCDATE();

set @DiscoverySourceId = dbo.fn_DiscoverySourceId_User();

 

DECLARE EntitiesToBeRemovedCursor CURSOR LOCAL FORWARD_ONLY READ_ONLY FOR

SELECT TME.[TypedManagedEntityid]

FROM MTV_HealthService HS

INNER JOIN dbo.[BaseManagedEntity] BHS

ON BHS.[BaseManagedEntityId] = HS.[BaseManagedEntityId]

— get host managed computer instances

INNER JOIN dbo.[TypedManagedEntity] TME

ON TME.[BaseManagedEntityId] = BHS.[TopLevelHostEntityId]

AND TME.[IsDeleted] = 0

INNER JOIN dbo.[DerivedManagedTypes] DMT

ON DMT.[DerivedTypeId] = TME.[ManagedTypeId]

INNER JOIN dbo.[ManagedType] BT

ON DMT.[BaseTypeId] = BT.[ManagedTypeId]

AND BT.[TypeName] = N’Microsoft.Windows.Computer’

— only with missing primary

LEFT OUTER JOIN dbo.Relationship HSC

ON HSC.[SourceEntityId] = HS.[BaseManagedEntityId]

AND HSC.[RelationshipTypeId] = dbo.fn_RelationshipTypeId_HealthServiceCommunication()

AND HSC.[IsDeleted] = 0

INNER JOIN DiscoverySourceToTypedManagedEntity DSTME

ON DSTME.[TypedManagedEntityId] = TME.[TypedManagedEntityId]

AND DSTME.[DiscoverySourceId] = @DiscoverySourceId

WHERE HS.[IsAgent] = 1

AND HSC.[RelationshipId] IS NULL;

 

OPEN EntitiesToBeRemovedCursor

 

FETCH NEXT FROM EntitiesToBeRemovedCursor

INTO @TypedManagedEntityId

 

WHILE @@FETCH_STATUS = 0

BEGIN

BEGIN TRAN

 

— Delete entity

EXEC @LastErr = [p_RemoveEntityFromDiscoverySourceScope] @TypedManagedEntityId, @DiscoverySourceId, @TimeGenerated;

IF @LastErr <> 0

GOTO Err

 

COMMIT TRAN

 

— Get the next typedmanagedentity to delete.

FETCH NEXT FROM EntitiesToBeRemovedCursor

INTO @TypedManagedEntityId

END

 

CLOSE EntitiesToBeRemovedCursor

DEALLOCATE EntitiesToBeRemovedCursor

 

GOTO Done

 

Err:

ROLLBACK TRAN

GOTO Done

 

Done: