Pavleck.Com

ULTIMA RATIO REGUM

  • Flickr Photos

    www.flickr.com
  • Things

    www.flickr.com
    This is a Flickr badge showing public photos from Jeremy Pavleck. Make your own badge here.


  • Listening To

  • Twitter

  • I Support

    Bloggers' Rights at EFF

  • Spam Blocked

  • last.fm records

    1. Made of Bricks Made of Bricks
      Kate Nash
    2. Eazy Duz It Eazy Duz It
      Eazy-E
    3. Swass Swass
      Sir Mix-a-Lot
    4. Blue Horse Blue Horse
      The Be Good Tanyas
    5. The Greatest Hits: Why Try Harder The Greatest Hits: Why Try Harder
      Fatboy Slim
    6. Punk in Drublic Punk in Drublic
      NOFX

Archive for the 'PowerShell' Category


SCOM2007: Determine Agent From Health Service ID

Posted by Jeremy on 16th May 2008

System Center Operations Manager 2007 is great, don’t get me wrong. But it does have it’s oddities - and one of those are messages such as these:

Details:Health service ( A63BAA7B-20B1-D6C0-75B9-8A8CE3DD7E02 ) should not generate data about this managed object ( 021971E6-1EFB-E123-7E2A-452ADB511016 ).

Now, we know that Health Service ID is referring to a specific agent, but which one? Luckily, this is fairly easy to figure out. Just hop onto the database server and run the following query:

  1. SELECT DisplayName FROM BaseManagedEntity WHERE BaseManagedEntityId = ‘THE ID’

It should return the DisplayName property of said ID, which is the agent you’re looking for.

In fact, to go a step further - if you have many queries like this, you could write a PowerShell function to simplify things for you - here’s a real rough outline:

  1. function Get-AgentByHSID ([string]$hsid)
  2. {
  3. $omdbserver = "<Set Your DB Name Here>"
  4. $omdb = "OperationsManager"
  5.  
  6. $cn = new-object system.data.SqlClient.SqlConnection("Data Source=$omdbserver;Initial Catalog=$omdb;Integrated Security=SSPI;");
  7. $ds = New-Object "System.Data.DataSet" "AgentName"
  8. $q = "Select DisplayName from BaseManagedEntity where BaseManagedEntityId = ‘$HSID’"
  9. $da = new-object "System.Data.SqlClient.SqlDataAdapter" ($q, $cn)
  10. $da.Fill($ds)
  11. Write-Host "HSID $HSID is associated with the following agent:"
  12. $ds.tables
  13. }

Like I said, the script is fairly basic and assumes a trust relationship with the database. It also expects a valid HSID - I’ll clean it up later. Edit the script, entering in your SCOM DB and DB Name if necessary, then add it to your $PROFILE. Then it’s as simple as Get-AgentByHSID “long health service guid” and it does all the heavy lifting.

Posted in Information Technology, PowerShell, Scripting | No Comments »

VBScript: How to find out if the current machine has PowerShell installed

Posted by Jeremy on 10th March 2008

In the MS Press book “Windows PowerShell Scripting Guide” one of the first scripts listed is how to detect, via WMI & VBScript, whether or not PowerShell is installed.

In the book, it says that the best way to locate PowerShell is to use it’s QFE hotfix ID, which is listed as “928439″. This will only work with Windows Vista. If you’re using Windows XP or Windows 2003, the hotfix number if PowerShell is installed will be “926139″.

I’ve edited the original script included with the MS Press book and have added a function to determine which OS we’re looking at, then search for the corresponding hotfix ID.

In the book, it says that the best way to locate PS is to use it’s QFE hotfix ID, which is “928439″. This is, however, an incorrect hotfix ID, at least now. The most current one is 926139, which is listed as SP3. I assume 928439 was the original number, before SP3 was thought of. Not to mention, they improperly format the WMI query, so even if you used the correct number, it wouldn’t show. Note: This is on Windows XP SP2, I’m unsure if this is on other versions as well.

  1.  
  2. ‘==========================================================================
  3.  
  4.  
  5. ‘ NAME: FindPowerShell.vbs
  6.  
  7.  
  8. ‘ AUTHOR: Jeremy D. Pavleck, based off original script by Ed Wilson , MS
  9.  
  10. ‘ EMAIL: JPavleck@GMail.com
  11.  
  12. ‘ DATE  : 03/11/2008
  13.  
  14.  
  15. ‘ COMMENT: Identifies if PowerShell is installed on the current machine or not.
  16.  
  17. ‘               Originally this script would only work under Vista, added additional
  18.  
  19. ‘               logic so it will work with other versions
  20.  
  21.  
  22. ‘==========================================================================
  23.  
  24. Option Explicit
  25.  
  26. dim strComputer, wmiNS, wmiQuery, objWMIService, colItems, objItem, osItems, itemConst RtnImmedFwdOnly = &amp;h30 ‘iflags for ExecQuery method of swbemservices object
  27.  
  28. strComputer = "."
  29.  
  30. wmiNS = "\root\cimv2"
  31.  
  32. Set objWMIService = GetObject("winmgmts:\\" &amp; strComputer &amp; wmiNS)
  33.  
  34. Set osItems = objWMIService.ExecQuery("SELECT * FROM Win32_OperatingSystem",,48) ‘ Query WMI for OS information
  35.  
  36. For Each item In osItems
  37.  
  38.  If Left(item.Version, 1) = 5 Then ‘ Windows XP, 2000 &amp; 2003 are version 5
  39.  
  40.  wmiQuery = "Select * from win32_QuickFixEngineering where hotfixid like ‘%926139%’" ‘ For XP &amp; Windows 2003
  41.  
  42.  ElseIf Left(item.Version, 1) = 6 Then ‘ Windows Vista &amp; (Presumably Server 2008) are version 6
  43.  
  44.  wmiQuery = "Select * from win32_QuickFixEngineering where hotfixid like ‘%928439%’" ‘ For Vista
  45.  
  46.  Else
  47.  
  48.  WScript.Echo "Unable to determine OS version, quitting."
  49.  
  50.  WScript.Quit
  51.  
  52.  End If
  53.  
  54. Next
  55.  
  56. Set colItems = objWMIService.ExecQuery(wmiQuery,,RtnImmedFwdOnly) ‘ Now query for the hotifx, using the correct ID based on OS
  57.  
  58. For Each objItem in colItems
  59.  
  60.     Wscript.Echo "PowerShell is present on " &amp; objItem.CSName
  61.  
  62.     Wscript.quit
  63.  
  64. Next
  65.  
  66. WScript.Echo "Unable to locate PowerShell on local machine"

Posted in Information Technology, PowerShell, Scripting, VBScript | 1 Comment »