Hey, Scripting Guy! Quick-Hits Friday: The Scripting Guys Respond to a Bunch of Questions (12/25/09)

ScriptingGuy1

Bookmark and ShareIn this post:

 

How Can I Get a List of All Drivers Available to a Computer?

Hey, Scripting Guy! Question

Hey, Scripting Guy! I liked your articles about how to get a list of the installed device drivers. However, I want to get a list of all drivers available for installation in the Windows Vista driver store (in other words, a list of hardware supported, which might be several per driver). All I can find is a WMI class that does this on a Systems Management Server. Is it possible to make this information available to other computers?

— DV

 

Hey, Scripting Guy! AnswerHello DV,

Microsoft Scripting Guy Ed Wilson here. All drivers that are available to a computer are in the system root folder. Printer drivers all begin with the letters “prn”. Using this information, I can easily get a list of the available printer drivers by using the Get-ChildItem cmdlet and piping the results to the Where-Object cmdlet. This is shown here.

Get-AvailablePrinterDrivers.ps1

Get-ChildItem ((Get-Item Env:systemroot).value+”inf”) -Exclude *.pnf |
Where-Object { $_.name -match “prn” }


Can I Query IIS Via WMI?
 

Hey, Scripting Guy! Question

Hey Scripting Guy! I found that you can query Internet Information Server (IIS) via WMI, but you must install something separate. I have seen some of the basic things that people have asked you about IIS, but I am looking to see if webDAV is enabled. I could not find anything on Web service extensions.

— PJ

 

Hey, Scripting Guy! AnswerHello PJ,

Actually, IIS has long been queriable via WMI. For IIS in Windows Server 2008 R2, there are four options:

1.     You can use the “classic” WMI. They are the same WMI classes that were available in Windows Server 2003. When you add the IIS role, you choose IIS 6 management compatibility.

2.     In Windows Server 2008, there are new WMI classes. These are an additional check box, and are called IIS management Scripts and Tools.

3.     There are IIS cmdlets. The IIS page has extensive information about using these.

4.     There is a WinRM IIS Extension that can be added as a feature.

These options are configured via the Server Manager utility, as seen here:

Image of configuring options via Server Manager utility


If you are interested in using Windows PowerShell and WMI to manage your IIS Server, I have a chapter in the Microsoft Press Windows PowerShell Scripting Guide book that covers this topic.


 

<

p style=”MARGIN: 0in 0in 8pt” class=”MsoNormal”>

Tell Me More About Querying WMI Objects

Hey, Scripting Guy! Question

Hey, Scripting Guy! I have noticed that there are multiple ways to query a WMI object. I can use filter, query, where, and select. What is the difference? Does it depend on what you are querying, and is one faster than the other?

— EJ

 

Hey, Scripting Guy! AnswerHello EJ,

There are many ways of querying a WMI object. The one I use is the one that pops to mind at the time. If I am working interactively at the Windows PowerShell console, I will often use the alias for the Get-WmiObject cmdlet and the class parameter in the first position without naming the parameter. This is shown here:

Gwmi WIN32_bios

Using the gwmi alias and the WMI class name is faster than spelling out the gwmi alias with the –query parameter. This is seen here:

gwmi –query “Select * from WIN32_bios”

From a results standpoint, both the –query parameter and the -class parameter return the same objects.

The two commands are a lot faster than VBScript (even faster than Scriptomatic). Keep in mind the methods are the same. You may want to look at the WMI Week of Hey, Scripting Guy! articles.

At times, however, I need to use a particular method or functionality because of what I am doing. In general, I would say you should use the syntax that feels natural. When working at the Windows PowerShell command line, I almost never use the –query parameter anymore. I instead use –class filter. I seldom use –property to filter out properties; instead, I generally return the entire object and deal with it in the output in the pipeline. Here are examples of that:

Get-Wmiobject –class WIN32_process –property name
PS C:> Get-Wmiobject -class WIN32_process -property name


__GENUS          : 2
__CLASS          : Win32_Process
__SUPERCLASS     :
__DYNASTY        :
__RELPATH        :
__PROPERTY_COUNT : 1
__DERIVATION     : {}
__SERVER         :
__NAMESPACE      :
__PATH           :
Name             : System Idle Process

__GENUS          : 2
__CLASS          : Win32_Process
__SUPERCLASS     :
__DYNASTY        :
__RELPATH        :
__PROPERTY_COUNT : 1
__DERIVATION     : {}
__SERVER         :
__NAMESPACE      :
__PATH           :
Name             : System

__GENUS          : 2
__CLASS          : Win32_Process
__SUPERCLASS     :
__DYNASTY        :
__RELPATH        :
__PROPERTY_COUNT : 1
__DERIVATION     : {}
__SERVER         :
__NAMESPACE      :
__PATH           :
<output truncated …>
Get-WmiObject –Class WIN32_Process | Select name
name
—-
System Idle Process
System
smss.exe
csrss.exe
wininit.exe
csrss.exe
services.exe
<output truncated …>

As you can see from the two commands above, the second output is much cleaner. Because of the way that Windows PowerShell returns the system properties as well as the specific property requested in the –property parameter, I always use the second syntax.

 

 

Tell Me More About the WMI Shadow Copy Class

Hey, Scripting Guy! Question

Hey Scripting Guy! I need to collect the Volume Shadow Copy configuration status for more than 500 servers. My requirement is to find out which disk has Visual Source Safe (VSS) enabled. Could you help me? I have tried the List All Shadow Copies on a Computer script, and it is giving the output seen here:

ID: {22eb30e2-5c49-4364-bdea-e2149f04524f}
Client accessible: True
Count: 1
Device object: \?GLOBALROOTDeviceHarddiskVolumeShadowCopy1
Differential: True
Exposed locally: False
Exposed name:
Exposed remotely: False
Hardware assisted: False
Imported: False
No auto release: True
Not surfaced: False
No writers: True
Originating machine: css.nwtraders.com
Persistent: True
Plex: False
Provider ID: {b5946137-7b9f-4925-af80-51abd60b20d5}
Service machine: css.nwtraders.com
Set ID: {6378b765-4392-44a8-8d25-e4faa6ac8250}
State: 12
Transportable: False
Volume name:
\?Volume{e0eb9433-beca-11dd-8163-806e6f6e6963}

By using the above output, I see that one drive has VSS enabled. However, it does not clearly tell me which drive has VSS enabled. Can you help me?

— GK

 

Hey, Scripting Guy! AnswerHello GK,

MSDN documents the WMI shadow copy class. If your volume name is not visible, due to it being hidden, you will need to query the Win32_ShadowVolumeSupport association class.

 

 

Troubleshooting an HTA Script

Hey, Scripting Guy! Question

Hey, Scripting Guy! I am trying to create an HTA script that will allow me to use standard Open/Save dialog boxes, so that the client computer can browse for a file or folder and select it, passing the selected item back to my HTA script for processing. This project sounded simple enough. I know that this could be done under Windows XP, but all our machines are currently running Windows Vista.