Wednesday 23 February 2011

Operations Manager (SCOM) 2007 - How to remove cluster objects from scom when computer objects in cluster cannot be deleted

This is variation of previous posts like these ones I just use remove-disabledmonitoringobject for the last steps which I think is safer.

Find agentless objects in agentless managed view. In our case they were cluster computer names and had a class of ‘windows computer’ and name = fqdn of the cluster server name. (not the two servers that hosted it). The agent machines were already decom but couldn’t be deleted from scom. The proxy agent pointed at a node we were trying to delete but couldn’t

In sql find it in bme table by query
SELECT     BaseManagedEntityId, BaseManagedEntityInternalId, BaseManagedTypeId, FullName, Path, Name, DisplayName, TopLevelHostEntityId, IsManaged,
                      IsDeleted, LastModified, OverrideTimestamp
FROM         BaseManagedEntity
WHERE     (Name LIKE '%CLUSTERXYZ%') AND (FullName LIKE '%Computer%')
ORDER BY FullName

Copy the FIRST column BaseManagedEntityID e.g
fc798482-69b4-d04c-642f-93f1c8d80b8b

run a select by ID to be 900% certain you have the right object
SELECT * FROM dbo.[BasemanagedEntity] where
BaseManagedEntityID='fc798482-69b4-d04c-642f-93f1c8d80b8b'

You should get 1 result with correct looking name etc.

Then run the update query to make scom think it is deleted
BE INSANELY CAREFUL RUNNING THIS QUERY – SCREW UP THE WHERE CLAUSE AND YOU WILL DESTROY SCOM. MAKE SURE THE UPDATE CAN ONLY TARGET THE ONE OBJECT THAT IS VALID
UPDATE dbo.[BasemanagedEntity]
SET IsDeleted = 1
where BaseManagedEntityID='fc798482-69b4-d04c-642f-93f1c8d80b8b'

now refresh ‘agentless managed’ and problem object should have disappeared. Repeat this for any invalid clusters that still appear in agentless managed.
Now it will let you delete the agent’s machines from the cluster in agent managed view.

Open command shell and run this to clean up any mess.
Remove-DisabledMonitoringObject

This will find all the cluster class child objects and make them ‘is deleted’ etc. Some posts have this as a manual step with more db updates of multiple objects in BME table but I think this way is safer.

At this point the clusters should disappear from 'monitoring' views.

Monday 21 February 2011

vbscript determine local timezone and UTC time

I've found it quite hard in the past to find script snippets on net for vbscript when you need to convert between UTC and local time in vbscript.

This has been useful for me in scripts that access database data that's stored in UTC (for example MOM & SCOM).

' UTC and dd mm yyyy vbscript code example

' Rick Jury

' ShowUTCTimeNow = Vbscript code to extract a UTC time for local machine using WMI

' DateRegion = show if dd/mm/yyyy or not in regional settings

' Also shows how to calculate the time offset from local time vs UTC.

 

' I couldn't find any working examle of how to make vbscript show a UTC time instead of local time so wrote one using WMI.

' note - ActiveTimeBias used in some code doesn't work on my vista machine as its a big dword.

 

' call function to show my utc time not local time.

MyUTCTime = ShowUTCTimeNow

wscript.echo "local UTC time is: " & MyUTCTime

 

' call a function to show dd mm yyyy format

MyFormat = DateRegion

wscript.echo "d m y format locally is: " & MyFormat

 

' Now how to figure out how many hours we currently off UTC allowing regardless incliding daylight savings

' returns difference of utc to now to HourOffset

wscript.echo "Current Offset in hours is: " & DateDiff("h",MyUTCTime,now)

 

Function ShowUTCTimeNow ()

                ' returns a string representing current UTC time but represented in typical vbscript acceptable date format 

 

                Const wbemFlagReturnImmediately = &h10

                Const wbemFlagForwardOnly = &h20

 

   Set objWMIService = GetObject("winmgmts:\\" & "." & "\root\CIMV2")

   Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_UTCTime", "WQL", _

                                                                                                                                                                  wbemFlagReturnImmediately + wbemFlagForwardOnly)

 

                For Each objItem In colItems

     ' WScript.Echo "Day: " & objItem.Day

'      WScript.Echo "DayOfWeek: " & objItem.DayOfWeek

'      WScript.Echo "Hour: " & objItem.Hour

'      WScript.Echo "Milliseconds: " & objItem.Milliseconds

'      WScript.Echo "Minute: " & objItem.Minute

'      WScript.Echo "Month: " & objItem.Month

'      WScript.Echo "Quarter: " & objItem.Quarter

'      WScript.Echo "Second: " & objItem.Second

'      WScript.Echo "WeekInMonth: " & objItem.WeekInMonth

'      WScript.Echo "Year: " & objItem.Year

                                If DateRegion = "US" Then

                                                ShowUTCTimeNow = objItem.Month & "/" & objItem.Day & "/" &objItem.Year & " " & objItem.Hour & ":"&objItem.Minute & ":" & objItem.Second

                                Else

                                                ShowUTCTimeNow = objItem.Day & "/" & objItem.Month & "/" &objItem.Year & " " & objItem.Hour & ":"&objItem.Minute & ":" & objItem.Second

                                End If

   Next

 

End Function

 

Function DateRegion()

                ' This function identifies if you are running mm/dd/yyyy or dd/mm/yyyy

                ' knowing this is critical if you are converting string to date etc.

                If DatePart("D","12/06/2007") = "12" Then

                                DateRegion= "NZ"

                Else

                                DateRegion= "US"

                End If

End Function

blog content

hi this blog will include technical comments, discoveries and other interesting things of note in the specialist subject areas I am interested in in the enterprise system management tools space and some other areas of IT I'm interested in like vbscript.