{"id":52213,"date":"2009-10-20T00:01:00","date_gmt":"2009-10-20T00:01:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2009\/10\/20\/hey-scripting-guy-part-2-how-can-i-make-sure-that-a-wmi-provider-exists-before-using-it-in-a-script\/"},"modified":"2009-10-20T00:01:00","modified_gmt":"2009-10-20T00:01:00","slug":"hey-scripting-guy-part-2-how-can-i-make-sure-that-a-wmi-provider-exists-before-using-it-in-a-script","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/hey-scripting-guy-part-2-how-can-i-make-sure-that-a-wmi-provider-exists-before-using-it-in-a-script\/","title":{"rendered":"Hey, Scripting Guy! Part 2: How Can I Make Sure That a WMI Provider Exists Before Using It in a Script?"},"content":{"rendered":"<p><!-- AddThis Button BEGIN --><a class=\"addthis_button\" href=\"http:\/\/www.addthis.com\/bookmark.php?v=250&amp;pub=scriptingguys\"><img decoding=\"async\" alt=\"Bookmark and Share\" src=\"http:\/\/s7.addthis.com\/static\/btn\/v2\/lg-share-en.gif\" width=\"125\" height=\"16\"><\/a>  <\/p>\n<p>(<strong>Editor&#8217;s note<\/strong>: This is part 2 of a two-part article originally intended for <em>TechNet Magazine<\/em>. Part 1 was published <a title=\"yesterday\" href=\"http:\/\/blogs.technet.com\/heyscriptingguy\/archive\/2009\/10\/19\/hey-scripting-guy-october-19-2009.aspx\">yesterday<\/a>.)&nbsp;<\/p>\n<p class=\"MsoNormal\">&nbsp;<\/p>\n<p class=\"MsoNormal\">To obtain information about the provider for a WMI class, you will need to open the class. Click the <b>Open Class<\/b> button, and type the name of the WMI class in the box that appears. We are looking for the provider name for the <b>Win32_Product<\/b> WMI class, and that is the name that you should type here. Click the <b>OK<\/b> button after you have typed and submitted the class name. The object editor for the <b>Win32_Product<\/b> WMI class now appears. This is seen in the following image. The first box of the object editor for <b>Win32_Product<\/b> lists the qualifiers. <b>Provider<\/b> is one of the qualifiers. WbemTest tells you the provider for <b>Win32_Product<\/b> is <b>MSIProv<\/b>.<\/p>\n<p class=\"MsoNormal\"><img decoding=\"async\" title=\"Image of object editor for Win32_Product WMI class\" alt=\"Image of object editor for Win32_Product WMI class\" src=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/qanda\/hsg\/2009\/october\/hey1019\/hsg-10-19-01.jpg\" width=\"483\" height=\"444\"><a href=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/qanda\/hsg\/2009\/october\/hey1019\/hsg-10-19-01.jpg\"><\/a><\/p>\n<p class=\"MsoNormal\"><br>You then assign the name of the WMI provider to the <b>$providerName<\/b> variable as seen here: <\/p>\n<p class=\"CodeBlock\"><font face=\"Lucida Sans Typewriter\"><span>$providerName = &#8220;MSIProv&#8221;<\/span><span><\/p>\n<p><\/span><\/font><\/p>\n<p class=\"MsoNormal\">The resulting object is stored in the <b>$provider<\/b> variable. This is seen here: <\/p>\n<p class=\"CodeBlock\"><font face=\"Lucida Sans Typewriter\"><span>&nbsp;$provider =&nbsp; Get-WmiObject -Class __provider -filter &#8220;name = &#8216;$providerName'&#8221;<\/span><span><\/p>\n<p><\/span><\/font><\/p>\n<p class=\"MsoNormal\">If the provider was not found, there will be no value in the <b>$provider<\/b> variable. You can therefore see if the <b>$provider<\/b> variable is null. If the <b>$provider<\/b> variable is not equal to null, the class ID of the provider is retrieved. The class ID of the WMI provider is stored in the <b>clsID<\/b> property. This is seen here: <\/p>\n<p class=\"CodeBlock\"><span><font face=\"Lucida Sans Typewriter\">&nbsp;If($provider -ne $null)<\/font><\/span><span><br><\/span><span><font face=\"Lucida Sans Typewriter\">&nbsp;&nbsp; {<\/font><\/span><span><br><\/span><font face=\"Lucida Sans Typewriter\"><span>&nbsp;&nbsp;&nbsp; $clsID = $provider.clsID<\/span><span><\/p>\n<p><\/span><\/font><\/p>\n<p class=\"MsoNormal\">If the function was run with the verbose parameter, the <b>$VerbosePreference<\/b> variable is set to <b>Continue<\/b>. When the value of <b>$VerbosePreference<\/b> is equal to <b>continue<\/b>, the <b>Write-Verbose<\/b> cmdlet will display information on the console. On the other hand, if the value of the <b>$VerbosePreference<\/b> variable is equal to <b>SilentlyContinue<\/b>, the <b>Write-Verbose<\/b> cmdlet does not display anything. This makes it easy to implement tracing features in a function without needing to create extensive test conditions. When the function is called with the <b>Verbose<\/b> parameter, the class ID of the provider is displayed. This is seen here: <\/p>\n<p class=\"CodeBlock\"><span><font face=\"Lucida Sans Typewriter\">&nbsp;&nbsp;&nbsp; Write-Verbose &#8220;$providerName WMI provider found. ClsID is $($clsID)&#8221;<\/font><\/span><span><br><\/span><font face=\"Lucida Sans Typewriter\"><span>&nbsp;&nbsp; }<\/span><span><\/p>\n<p><\/span><\/font><\/p>\n<p class=\"MsoNormal\">If the WMI provider is not found, the function returns <b>false<\/b> to the calling code. This is seen here: <\/p>\n<p class=\"CodeBlock\"><span><font face=\"Lucida Sans Typewriter\">&nbsp;Else<\/font><\/span><font face=\"Lucida Sans Typewriter\"><span> <br><\/span><span>&nbsp;&nbsp; {<\/span><\/font><span><br><\/span><span><font face=\"Lucida Sans Typewriter\">&nbsp;&nbsp;&nbsp;&nbsp; Return $false<\/font><\/span><span><br><\/span><font face=\"Lucida Sans Typewriter\"><span>&nbsp;&nbsp; }<\/span><span><\/p>\n<p><\/span><\/font><\/p>\n<p class=\"MsoNormal\">The next thing the function does is check the registry to ensure the WMI provider has been properly registered with DCOM. Once again, the <b>Write-Verbose<\/b> cmdlet is used to provide feedback about the status of the provider check. This is seen here: <\/p>\n<p class=\"CodeBlock\"><font face=\"Lucida Sans Typewriter\"><span>&nbsp;&nbsp; Write-Verbose &#8220;Checking for proper registry registration &#8230;&#8221;<\/span><span><\/p>\n<p><\/span><\/font><\/p>\n<p class=\"MsoNormal\">To search the registry for the WMI provider registration, the Windows PowerShell registry provider is used. By default, there is no Windows PowerShell drive for the <b>HKEY_CLASSES_ROOT<\/b> registry hive. However, it is not a given that one would not have created such a drive in their Windows PowerShell profile. To avoid a potential error that might arise when creating a Windows PowerShell drive for the <b>HKEY_CLASSES_ROOT<\/b> hive, the <b>Test-Path<\/b> cmdlet is used to check to see if a <b>HKCR:<\/b> drive exists. If the <b>HKCR:<\/b> drive does exist, it will be used and the <b>Write-Verbose<\/b> cmdlet is used to display a status message that states the <b>HKCR:<\/b> drive was found and that the search is commencing for the class ID of the WMI provider. This is seen here: <\/p>\n<p class=\"CodeBlock\"><span><font face=\"Lucida Sans Typewriter\">&nbsp;&nbsp; If(Test-Path -path HKCR:)<\/font><\/span><span><br><\/span><span><font face=\"Lucida Sans Typewriter\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<\/font><\/span><span><br><\/span><font face=\"Lucida Sans Typewriter\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Write-Verbose &#8220;HKCR: drive found. Testing for $clsID&#8221;<\/span><span><\/p>\n<p><\/span><\/font><\/p>\n<p class=\"MsoNormal\">To detect if the WMI provider is registered with DCOM, all that is necessary is to see if the class ID of the WMI provider is present in the CLSID section of <b>HKEY_CLASSES_ROOT<\/b>. The best way to check for the presence of the registry key is to use the <b>Test-Path<\/b> cmdlet. This is seen here: <\/p>\n<p class=\"CodeBlock\"><span><font face=\"Lucida Sans Typewriter\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Test-path -path (Join-Path -path HKCR:CLSID -childpath $clsID)<\/font><\/span><font face=\"Lucida Sans Typewriter\"><span>&nbsp; <br><\/span><span>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;}<\/span><span><\/p>\n<p><\/span><\/font><\/p>\n<p class=\"MsoNormal\">On the other hand, if there is no <b>HKCR:<\/b> drive on the computer, you can go ahead and create one. You could search for the existence of a drive that is rooted in <b>HKEY_CLASSES_ROOT<\/b>, and if you found it, you could then use the Windows PowerShell drive in your query. To find if there are any Windows PowerShell drives rooted in <b>HKEY_CLASSES_ROOT<\/b>, you could use the <b>Get-PSDrive<\/b> cmdlet as seen here: <\/p>\n<p class=\"CodeBlock\"><span><font face=\"Lucida Sans Typewriter\">Get-PSDrive | Where-Object { $_.root -match &#8220;classes&#8221; } |<\/font><\/span><font face=\"Lucida Sans Typewriter\"><span> <br><\/span><span>Select-Object name<\/span><span><\/p>\n<p><\/span><\/font><\/p>\n<p class=\"MsoNormal\">But to be honest, it is more trouble than it is worth. There is nothing wrong with having multiple Windows PowerShell drives mapped to the same resource. Therefore, if there is not an <b>HKCR:<\/b> drive, the <b>Write-Verbose<\/b> cmdlet is used to display a message that the drive does not exist and will be created. This is seen here: <\/p>\n<p class=\"CodeBlock\"><span><font face=\"Lucida Sans Typewriter\">&nbsp;&nbsp; Else<\/font><\/span><span><br><\/span><span><font face=\"Lucida Sans Typewriter\">&nbsp;&nbsp;&nbsp;&nbsp; {<\/font><\/span><span><br><\/span><font face=\"Lucida Sans Typewriter\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Write-Verbose &#8220;HKCR: drive not found. Creating same.&#8221;<\/span><span> <\/p>\n<p><\/span><\/font><\/p>\n<p class=\"MsoNormal\">To create a new Windows PowerShell drive, you use the <b>New-PSDrive<\/b> cmdlet to specify the name for the Windows PowerShell drive and the root location of the drive. Because this is going to be a registry drive, you will use the registry provider. When a Windows PowerShell drive is created, it displays feedback on the Windows PowerShell console. This feedback is seen here: <\/p>\n<p class=\"CodeBlock\"><span><font face=\"Lucida Sans Typewriter\">PS C:AutoDoc&gt; New-PSDrive -Name HKCR -PSProvider registry -Root Hkey_Classes_Ro<br>ot<\/font><\/span><span><\/p>\n<p><\/span><font face=\"Lucida Sans Typewriter\"><span>Name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Provider&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Root&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; CurrentLocation<br>&#8212;-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8212;&#8212;&#8211;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8212;-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8212;&#8212;&#8212;&#8212;&#8212;<br>HKCR&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Registry&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Hkey_Classes_Root<\/span><span><\/p>\n<p><\/span><\/font><\/p>\n<p class=\"MsoNormal\">The feedback from creating the registry drive can be distracting. To get rid of the feedback, you can pipe the results to the <b>Out-Null<\/b> cmdlet: <\/p>\n<p class=\"CodeBlock\"><font face=\"Lucida Sans Typewriter\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; New-PSDrive -Name HKCR -PSProvider registry -Root Hkey_Classes_Root | Out-Null<\/span><span><\/p>\n<p><\/span><\/font><\/p>\n<p class=\"MsoNormal\">After the Windows PowerShell registry drive has been created, it is time to check for the existence of the WMI provider class ID. Before that is done, the <b>Write-Verbose<\/b> cmdlet is used to provide feedback about this step of the operation: <\/p>\n<p class=\"CodeBlock\"><font face=\"Lucida Sans Typewriter\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Write-Verbose &#8220;Testing for $clsID&#8221;<\/span><span> <\/p>\n<p><\/span><\/font><\/p>\n<p class=\"MsoNormal\">The <b>Test-Path<\/b> cmdlet is used to check for the existence of the WMI provider class ID. To build the path to the registry key, the <b>Join-Path<\/b> cmdlet is used. The parent path is the <b>HKCR:<\/b> registry drive CLSID hive, and the child path is the WMI provider class ID that is stored in the <b>$clsID<\/b> variable. This is seen here: <\/p>\n<p class=\"CodeBlock\"><font face=\"Lucida Sans Typewriter\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Test-path -path (Join-Path -path HKCR:CLSID -childpath $clsID<\/span><span>)&nbsp; <\/p>\n<p><\/span><\/font><\/p>\n<p class=\"MsoNormal\">After the <b>Test-Path<\/b> cmdlet has been used to check for the existence of the WMI provider class ID, the <b>Write-Verbose<\/b> cmdlet is used to display a message stating that the test is complete: <\/p>\n<p class=\"CodeBlock\"><font face=\"Lucida Sans Typewriter\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Write-Verbose &#8220;Test complete.&#8221;<\/span><span><\/p>\n<p><\/span><\/font><\/p>\n<p class=\"MsoNormal\">It is a best practice to not make permanent modifications to the Windows PowerShell environment in a script. Therefore, you will want to remove the Windows PowerShell drive if it was created in the script. The <b>Write-Verbose<\/b> cmdlet is employed to provide a status update, and the <b>Remove-PSDrive<\/b> cmdlet is used to remove the <b>HKCR:<\/b> registry drive. To avoid cluttering the Windows PowerShell console, the result of removing the <b>HKCR:<\/b> registry drive is piped to the <b>Out-Null<\/b> cmdlet. This is seen here: <\/p>\n<p class=\"CodeBlock\"><span><font face=\"Lucida Sans Typewriter\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Write-Verbose &#8220;Removing HKCR: drive.&#8221;<\/font><\/span><font face=\"Lucida Sans Typewriter\"><span> <br><\/span><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Remove-PSDrive -Name HKCR | Out-Null<\/span><\/font><span><br><\/span><font face=\"Lucida Sans Typewriter\"><span>&nbsp;&nbsp;&nbsp;&nbsp; }<\/span><span><\/p>\n<p><\/span><\/font><\/p>\n<p class=\"MsoNormal\">The last thing that needs to be done is to set the <b>$VerbosePreference<\/b> back to the value that was stored in the <b>$oldVerbosePreference<\/b>. This line of code is executed even if no change to the <b>$VerbosePreference<\/b> is made. This is seen here: <\/p>\n<p class=\"CodeBlock\"><font face=\"Lucida Sans Typewriter\"><span>&nbsp; $VerbosePreference = $oldVerbosePreference<br>} #end Get-WmiProvider function<\/span><span><\/p>\n<p><\/span><\/font><\/p>\n<p class=\"MsoNormal\">The entry point to the script assigns a value to the <b>$providerName<\/b> variable: <\/p>\n<p class=\"CodeBlock\"><font face=\"Lucida Sans Typewriter\"><span>$providerName = &#8220;msiprov&#8221;<\/span><span><\/p>\n<p><\/span><\/font><\/p>\n<p class=\"MsoNormal\">The <b>Get-WmiProvider<\/b> function is called and it passes both the WMI provider name that is stored in the <b>$providerName<\/b> variable and the <b>verbose<\/b> switched parameter. The <b>if<\/b> statement is used because the <b>Get-WmiProvider<\/b> function returns a Boolean value (true or false): <\/p>\n<p class=\"CodeBlock\"><font face=\"Lucida Sans Typewriter\"><span>&nbsp;if(Get-WmiProvider -providerName $providerName&nbsp; -verbose )<\/span><span> <\/p>\n<p><\/span><\/font><\/p>\n<p class=\"MsoNormal\">If the return from the <b>Get-WmiProvider<\/b> function is true, the WMI class supported by the WMI provider is queried by using the <b>Get-WMiObject<\/b> cmdlet. This is seen here: <\/p>\n<p class=\"CodeBlock\"><span><font face=\"Lucida Sans Typewriter\">&nbsp; {<\/font><\/span><span><font face=\"Lucida Sans Typewriter\"> <br><\/font><\/span><span><br><font face=\"Lucida Sans Typewriter\">&nbsp;&nbsp;&nbsp; Get-WmiObject -class win32_product<\/font><\/span><span><br><\/span><span><br><font face=\"Lucida Sans Typewriter\">&nbsp; }<\/font><\/span><span><font face=\"Lucida Sans Typewriter\"> <\/p>\n<p><\/font><\/span><\/p>\n<p class=\"MsoNormal\">If the WMI provider is not found, a message that states the WMI provider is not found is displayed on the console: <\/p>\n<p class=\"CodeBlock\"><span><font face=\"Lucida Sans Typewriter\">else<\/font><\/span><span><br><\/span><span><font face=\"Lucida Sans Typewriter\">&nbsp; {<\/font><\/span><span><br><\/span><span><font face=\"Lucida Sans Typewriter\">&nbsp;&nbsp; &#8220;$providerName provider not found&#8221;<\/font><\/span><font face=\"Lucida Sans Typewriter\"><span> <br><\/span><span>&nbsp; }<\/span><span><\/p>\n<p><\/span><\/font><\/p>\n<p class=\"MsoNormal\">The entire Get-WmiProviderFunction.ps1 script is shown here:<\/p>\n<p class=\"CodeBlockScreenedHead\"><strong>Figure 3&nbsp; Get-WmiProviderFunction.ps1<\/strong><\/p>\n<p class=\"CodeBlock\"><span><font face=\"Lucida Sans Typewriter\">Function Get-WmiProvider([string]$providerName, [switch]$verbose)<\/font><\/span><span><br><\/span><span><font face=\"Lucida Sans Typewriter\">{<\/font><\/span><span><br><\/span><span><font face=\"Lucida Sans Typewriter\">&nbsp;$oldVerbosePreference = $VerbosePreference<\/font><\/span><span><br><\/span><span><font face=\"Lucida Sans Typewriter\">&nbsp;if($verbose) { $VerbosePreference = &#8220;continue&#8221; }<\/font><\/span><span><br><\/span><span><font face=\"Lucida Sans Typewriter\">&nbsp;$provider =&nbsp; Get-WmiObject -Class __provider -filter &#8220;name = &#8216;$providerName'&#8221;<\/font><\/span><span><br><\/span><span><font face=\"Lucida Sans Typewriter\">&nbsp;If($provider -ne $null)<\/font><\/span><span><br><\/span><span><font face=\"Lucida Sans Typewriter\">&nbsp;&nbsp; {<\/font><\/span><span><br><\/span><span><font face=\"Lucida Sans Typewriter\">&nbsp;&nbsp;&nbsp; $clsID = $provider.clsID<\/font><\/span><span><br><\/span><span><font face=\"Lucida Sans Typewriter\">&nbsp;&nbsp;&nbsp; Write-Verbose &#8220;$providerName WMI provider found. ClsID is $($clsID)&#8221;<\/font><\/span><span><br><\/span><span><font face=\"Lucida Sans Typewriter\">&nbsp;&nbsp; }<\/font><\/span><span><br><\/span><span><font face=\"Lucida Sans Typewriter\">&nbsp;Else<\/font><\/span><font face=\"Lucida Sans Typewriter\"><span> <br><\/span><span>&nbsp;&nbsp; {<\/span><\/font><span><br><\/span><span><font face=\"Lucida Sans Typewriter\">&nbsp;&nbsp;&nbsp;&nbsp; Return $false<\/font><\/span><span><br><\/span><span><font face=\"Lucida Sans Typewriter\">&nbsp;&nbsp; }<\/font><\/span><span><br><\/span><span><font face=\"Lucida Sans Typewriter\">&nbsp;&nbsp; Write-Verbose &#8220;Checking for proper registry registration &#8230;&#8221;<\/font><\/span><span><br><\/span><span><font face=\"Lucida Sans Typewriter\">&nbsp;&nbsp; If(Test-Path -path HKCR:)<\/font><\/span><span><br><\/span><span><font face=\"Lucida Sans Typewriter\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<\/font><\/span><span><br><\/span><span><font face=\"Lucida Sans Typewriter\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Write-Verbose &#8220;HKCR: drive found. Testing for $clsID&#8221;<\/font><\/span><span><br><\/span><span><font face=\"Lucida Sans Typewriter\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Test-path -path (Join-Path -path HKCR:CLSID -childpath $clsID)<\/font><\/span><font face=\"Lucida Sans Typewriter\"><span>&nbsp; <br><\/span><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<\/span><\/font><span><br><\/span><span><font face=\"Lucida Sans Typewriter\">&nbsp;&nbsp; Else<\/font><\/span><span><br><\/span><span><font face=\"Lucida Sans Typewriter\">&nbsp;&nbsp;&nbsp;&nbsp; {<\/font><\/span><span><br><\/span><span><font face=\"Lucida Sans Typewriter\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Write-Verbose &#8220;HKCR: drive not found. Creating same.&#8221;<\/font><\/span><font face=\"Lucida Sans Typewriter\"><span> <br><\/span><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; New-PSDrive -Name HKCR -PSProvider registry -Root Hkey_Classes_Root | Out-Null<\/span><\/font><span><br><\/span><span><font face=\"Lucida Sans Typewriter\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Write-Verbose &#8220;Testing for $clsID&#8221;<\/font><\/span><font face=\"Lucida Sans Typewriter\"><span> <br><\/span><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Test-path -path (Join-Path -path HKCR:CLSID -childpath $clsID)<\/span><\/font><font face=\"Lucida Sans Typewriter\"><span>&nbsp; <br><\/span><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Write-Verbose &#8220;Test complete.&#8221;<\/span><\/font><span><br><\/span><span><font face=\"Lucida Sans Typewriter\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Write-Verbose &#8220;Removing HKCR: drive.&#8221;<\/font><\/span><font face=\"Lucida Sans Typewriter\"><span> <br><\/span><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Remove-PSDrive -Name HKCR | Out-Null<\/span><\/font><span><br><\/span><span><font face=\"Lucida Sans Typewriter\">&nbsp;&nbsp;&nbsp;&nbsp; }<\/font><\/span><span><br><\/span><span><font face=\"Lucida Sans Typewriter\">&nbsp; $VerbosePreference = $oldVerbosePreference<\/font><\/span><span><br><\/span><span><font face=\"Lucida Sans Typewriter\">} #end Get-WmiProvider function<\/font><\/span><span><\/p>\n<p><\/span><span><font face=\"Lucida Sans Typewriter\"># *** Entry Point to Script ***<\/font><\/span><span><br><\/span><span><font face=\"Lucida Sans Typewriter\">$providerName = &#8220;msiprov&#8221;<\/font><\/span><span><br><\/span><span><font face=\"Lucida Sans Typewriter\">&nbsp;if(Get-WmiProvider -providerName $providerName&nbsp; -verbose )<\/font><\/span><font face=\"Lucida Sans Typewriter\"><span> <br><\/span><span>&nbsp; {<\/span><\/font><font face=\"Lucida Sans Typewriter\"><span> <br><\/span><span>&nbsp;&nbsp;&nbsp; Get-WmiObject -class win32_product<\/span><\/font><font face=\"Lucida Sans Typewriter\"><span> <br><\/span><span>&nbsp; }<\/span><\/font><font face=\"Lucida Sans Typewriter\"><span> <br><\/span><span>else<\/span><\/font><font face=\"Lucida Sans Typewriter\"><span> <br><\/span><span>&nbsp; {<\/span><\/font><font face=\"Lucida Sans Typewriter\"><span> <br><\/span><span>&nbsp;&nbsp; &#8220;$providerName provider not found&#8221;<\/span><\/font><font face=\"Lucida Sans Typewriter\"><span> <br><\/span><span>&nbsp; }<\/span><span><\/p>\n<p><\/span><\/font><\/p>\n<p class=\"MsoNormal\"><span><br>We hope you will find these techniques useful and that you will incorporate them into your daily scripting needs. We invite you to join us on the <a href=\"http:\/\/technet.microsoft.com\/en-us\/scriptcenter\/default.aspx\">Script Center<\/a> for the daily <a title=\"Hey, Scripting Guy! Blog post\" href=\"http:\/\/blogs.technet.com\/heyscriptingguy\/\">Hey, Scripting Guy! Blog post<\/a><\/span><span>. If you would like to be among the first to be informed about everything that is happening on the Script Center, you can <a href=\"https:\/\/twitter.com\/scriptingguys\/\">follow us on Twitter<\/a>. We also make postings over on the <a href=\"http:\/\/www.facebook.com\/group.php?gid=5901799452\">Scripting Guys group on Facebook<\/a>. If you get stuck some night while you are working on a script, you can post to the <a href=\"http:\/\/social.technet.microsoft.com\/Forums\/en\/ITCG\/threads\/\">Official Scripting Guys Forum<\/a>. We have an excellent group of moderators and other active members who are always willing to help other scripters. Of course, if you have questions, suggestions, or comments, you can always send us e-mail at <a href=\"http:\/\/blogs.technet.commailto:scripter@microsoft.com\"><font face=\"Segoe\">scripter@microsoft.com<\/font><\/a>.<\/span> <br><\/p>\n<p><b><span>Ed Wilson and Craig Liebendorfer, Scripting Guys<\/span><\/b><\/p>\n<p><b><span><\/span><\/b><\/p>\n","protected":false},"excerpt":{"rendered":"<p>(Editor&#8217;s note: This is part 2 of a two-part article originally intended for TechNet Magazine. Part 1 was published yesterday.)&nbsp; &nbsp; To obtain information about the provider for a WMI class, you will need to open the class. Click the Open Class button, and type the name of the WMI class in the box that [&hellip;]<\/p>\n","protected":false},"author":595,"featured_media":87096,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[3,4,45,6],"class_list":["post-52213","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-scripting-guy","tag-scripting-techniques","tag-windows-powershell","tag-wmi"],"acf":[],"blog_post_summary":"<p>(Editor&#8217;s note: This is part 2 of a two-part article originally intended for TechNet Magazine. Part 1 was published yesterday.)&nbsp; &nbsp; To obtain information about the provider for a WMI class, you will need to open the class. Click the Open Class button, and type the name of the WMI class in the box that [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/52213","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/users\/595"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/comments?post=52213"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/52213\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media\/87096"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media?parent=52213"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=52213"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=52213"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}