Summary: Learn how to use Windows PowerShell to detect the version of Internet Explorer that is running on your computer.
In this post:
Hey, Scripting Guy! How do I access the user Environment Variables such as "UserProfile" (normally available with the command prompt command "SET") in a VBS script?
Hello KW, Microsoft Scripting Guy Ed Wilson here. This can be done by either using the wshEnvironment object accessible via WshShell.environment or via WMI. Both techniques are illustrated on the Scripting Guys Script Repository. Here is a link to some scripts in the repository that will help.
Hey, Scripting Guy! Hey everyone! I am a first time writer, long time reader from back in the VBS days (which are still here at times). I have a question that I have not seen addressed. If it has, please just point me to the post. How do you Scripting Guys keep track of your "versions" of your Windows PowerShell scripts? I am constantly finding myself improving on my scripts with a tidbit here and a nugget there. Then when I want to share this with my co-workers, I have to email it around or save it to a shared drive. Then I normally make another change and have to repeat the process. There has to be something that people use to save versions of a script as it matures (like SourceSafe was used for Visual Basic Programs years ago), and I'd just like to know what people are using so that I can investigate them. Right now emailing around scripts or saving to a shared drive isn't exactly the most efficient use my time.
Hello KS. There are a number of ways to do this. One way is to use SharePoint to maintain your script library, and then you can check out the script when it needs to be modified. Internally, I manually keep track of a version number using major / minor versions. I increment the minor version when I make changes and the major version when I make significant additions (like 2.1). I used this same technique with VBScripts. Visual Studio, will automatically increment versions (if you tell it to) when compiling code but that does no good for scripts.
In the past, I used to use Visual Source Safe which was a cool tool to use. I used it for documents, as well as for scripts. I could easily run it standalone on my laptop. Unfortunately, we got rid of Visual Source Safe a couple of versions ago with Visual Studio (although it is still around, in the older versions of the product). The replacement product is an enterprise solution that is way too overkill for scripting.
There are community tools available, and Sapien will be releasing a version of Primal Script that will have (either in the product, or hooks for an additional product, not sure) support for source control. I think this will be cool, and will address a real need.
I know people who use Mesh, and Groove to move scripts around, and to help them to maintain source control. Mesh is cool because it replicates around a virtual network of computers. It does not, however, support versioning (I do not believe).
I have used the “Previous versions” feature of Windows (Vista and beyond, installable on Windows XP) to save myself from disaster. This feature allows you to roll back to a previous version of a script or other file and is way cool.
Note: the following is a multiple thread real example from a reader:
Hey, Scripting Guy! What’s the equivalent to MicrosoftIE_Summary in Windows Vista? I just need to get the version of IE.
Hello BC. You find this information by using this query:
reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer" /v Version | find "Version" | find "8.0"
Then checking %errorlevel% helps a lot!
KB article 164539 also provides help for identifying Internet Explorer versions.
Hey, Scripting Guy! Thanks for the help! One small problem though, the Windows PowerShell script is being run remotely from a Windows Server 2003 machine. I don’t believe I can remotely query the registry can I? This is being incorporated into an inventory script that runs server side. The script makes WMI queries and modifies a database accordingly. This is the only Windows Vista / Windows XP WMI compatibility issue I have run into so far.
Hello BC. You can use the StdRegProv WMI class to query the registry value. Here is a script I just wrote for you that illustrates the technique from inside Windows PowerShell.
# NAME: GetIEVersionWmi.Ps1
# AUTHOR: ed wilson, Microsoft
# DATE: 7/7/2009
# KEYWORDS: Registry, WMI, stdregprov
# COMMENTS: This script reads the registry by using WMI
# The hklm value comes from SDK and is a number
# The key value DOES NOT get a backslash in front of it!
# The value value is obvious
Param([string]$computer = $env:COMPUTERNAME)
$hklm = 2147483650
$key = "SOFTWARE\Microsoft\Internet Explorer"
$value = "Version"
$wmi = [wmiclass]"\\$computer\root\default:stdRegProv"
Hey, Scripting Guy! Sorry to bother you again, but when I put the computer name in the script and tried to run it, the results in the following figure is what I got:
I also tried it exactly as you sent it with much the same result.
Thanks in advance!
Hello BC. This is because this is a script, NOT command line commands. If you want to run from the command line, then do not use the param statement.
$computer= “My computer name goes here”
I would love you to follow me on Twitter or Facebook. If you have any questions, send email to me at email@example.com or post them on the Official Scripting Guys Forum. See you tomorrow. Until then, peace.
Ed Wilson, Microsoft Scripting Guy