Posted by Jeremy on 11th March 2008
In my post yesterday, I incorrectly assumed that the hotfix ID being used to query for the installation of PowerShell was wrong, probably due to an earlier release. The truth is there is a couple of hotfix IDs, depending on which operating system you’re on. If you’re on Windows XP, 2000 or 2003 you have one ID, if you’re on Vista or (presumably) 2008 it’s a completely different ID. I’ve since banged together a quick script to look for the OS version first, then to query for the proper fix. Hopefully you’ll find it useful!
Also, yesterday I got my Arduino starter kit! I haven’t gotten to play with it much at all, except for the hardware equivalent of “Hello World”, the blinking LED. I’m looking forward to using it when I get better and done with some work, especially since I have a few ideas kicking around. And I love this starter kit, it contains everything I need to get through LadyAda’s first set of tutorials - no rummaging for an hour in the parts bin, then going to RadioShack to find out they don’t stock it instore
Footnotes listed in the above post:
Posted in Hardware, Microcontrollers, VBScript | 1 Comment »
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.
-
-
‘==========================================================================
-
-
‘
-
-
‘ NAME: FindPowerShell.vbs
-
-
‘
-
-
‘ AUTHOR: Jeremy D. Pavleck, based off original script by Ed Wilson , MS
-
-
‘ EMAIL: JPavleck@GMail.com
-
-
‘ DATE : 03/11/2008
-
-
‘
-
-
‘ COMMENT: Identifies if PowerShell is installed on the current machine or not.
-
-
‘ Originally this script would only work under Vista, added additional
-
-
‘ logic so it will work with other versions
-
-
‘
-
-
‘==========================================================================
-
-
Option Explicit
-
-
dim strComputer, wmiNS, wmiQuery, objWMIService, colItems, objItem, osItems, itemConst RtnImmedFwdOnly = &h30 ‘iflags for ExecQuery method of swbemservices object
-
-
strComputer = "."
-
-
wmiNS = "\root\cimv2"
-
-
Set objWMIService = GetObject("winmgmts:\\" & strComputer & wmiNS)
-
-
Set osItems = objWMIService.ExecQuery("SELECT * FROM Win32_OperatingSystem",,48) ‘ Query WMI for OS information
-
-
For Each item In osItems
-
-
If Left(item.Version, 1) = 5 Then ‘ Windows XP, 2000 & 2003 are version 5
-
-
wmiQuery = "Select * from win32_QuickFixEngineering where hotfixid like ‘%926139%’" ‘ For XP & Windows 2003
-
-
ElseIf Left(item.Version, 1) = 6 Then ‘ Windows Vista & (Presumably Server 2008) are version 6
-
-
wmiQuery = "Select * from win32_QuickFixEngineering where hotfixid like ‘%928439%’" ‘ For Vista
-
-
Else
-
-
WScript.Echo "Unable to determine OS version, quitting."
-
-
WScript.Quit
-
-
End If
-
-
Next
-
-
Set colItems = objWMIService.ExecQuery(wmiQuery,,RtnImmedFwdOnly) ‘ Now query for the hotifx, using the correct ID based on OS
-
-
For Each objItem in colItems
-
-
Wscript.Echo "PowerShell is present on " & objItem.CSName
-
-
Wscript.quit
-
-
Next
-
-
WScript.Echo "Unable to locate PowerShell on local machine"
Posted in Information Technology, PowerShell, Scripting, VBScript | 1 Comment »