{"id":16891,"date":"2010-10-07T00:01:00","date_gmt":"2010-10-07T00:01:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2010\/10\/07\/reuse-powershell-code-to-simplify-script-creation\/"},"modified":"2010-10-07T00:01:00","modified_gmt":"2010-10-07T00:01:00","slug":"reuse-powershell-code-to-simplify-script-creation","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/reuse-powershell-code-to-simplify-script-creation\/","title":{"rendered":"Reuse PowerShell Code to Simplify Script Creation"},"content":{"rendered":"<p><b>Summary<\/b>: The Microsoft Scripting Guys describe how to reuse Windows PowerShell code to simplify script writing and retrieve reliability information.<\/p>\n<p>&nbsp;<\/p>\n<p><img decoding=\"async\" height=\"34\" width=\"34\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/q-for-powertip.jpg\" align=\"left\" alt=\"Hey, Scripting Guy! Question\" border=\"0\" title=\"Hey, Scripting Guy! Question\" \/> Hey, Scripting Guy! I really enjoy reading your stuff. It is generally both fun and informative. The thing I appreciate the most is that your writing does not read like standard product documentation. I am, however, not exactly clear how to use the <b>Test-ReliabilityProvider<\/b> function you developed <a href=\"http:\/\/blogs.technet.com\/b\/heyscriptingguy\/archive\/2010\/10\/06\/use-powershell-to-check-for-wmi-dependencies-on-windows-7.aspx\">yesterday<\/a>. Can you explain that to me please?<\/p>\n<p>&#8212; TE<\/p>\n<p>&nbsp;<\/p>\n<p><img decoding=\"async\" height=\"34\" width=\"34\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/a-for-powertip.jpg\" align=\"left\" alt=\"Hey, Scripting Guy! Answer\" border=\"0\" title=\"Hey, Scripting Guy! Answer\" \/> Hello TE, <\/p>\n<p>Microsoft Scripting Guy Ed Wilson here. It has been raining all day down here in Charlotte, <a href=\"http:\/\/en.wikipedia.org\/wiki\/North_Carolina\">North Carolina<\/a>, in the United States. With the cool temperatures outside (60 degrees Fahrenheit, 15.6 degrees Celsius), it has been an excellent day for drinking tea. Right now, I am sipping a cup of <a href=\"http:\/\/en.wikipedia.org\/wiki\/Darjeeling_tea\">Darjeeling tea<\/a> and munching on an <a href=\"http:\/\/en.wikipedia.org\/wiki\/Anzac_biscuit\">Anzac biscuit<\/a> while listening to Bon Jovi on my <a href=\"http:\/\/zune.net\/en-us\/products\/zunehd\/default.htm\">Zune HD<\/a>. TE, I can certainly understand your misgivings about using the <b>Test-ReliabilityProvider<\/b> function, because in Windows PowerShell, functions can act like cmdlets. Things can become muddled. <\/p>\n<p>I stored the <b>Test-ReliabilityProvider<\/b> function in a .ps1 Windows PowerShell script file, and added a line to the bottom of the file. The line is commented out to keep it from executing if you decide to <a href=\"http:\/\/blogs.technet.com\/heyscriptingguy\/archive\/2009\/12\/23\/hey-scripting-guy-december-23-2009.aspx\">dot-source<\/a> the file (something I will talk about in a little bit). The Test-ReliabilityProvider.ps1 script is shown here.<\/p>\n<blockquote>\n<p><strong>Test-ReliabilityProvider.ps1<\/strong><\/p>\n<p><span style=\"color: #000000\">Function<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">Test-ReliabilityProvider<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">{<\/span><span style=\"color: #808080\">&nbsp; <br \/>&nbsp; <\/span><span style=\"color: #000000\">&lt;<\/span><span style=\"color: #0000ff\">#<\/span><span style=\"color: #808080\"> <br \/>&nbsp;&nbsp; <\/span><span style=\"color: #000000\">.Synopsis<\/span><span style=\"color: #808080\"> <br \/>&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: #000000\">This<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">function<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">checks<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">for<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">the<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">presence<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">of<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">the<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">WMI<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">Reliability<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">provider<\/span><span style=\"color: #808080\"> <br \/>&nbsp;&nbsp; <\/span><span style=\"color: #000000\">.Description<\/span><span style=\"color: #808080\"> <br \/>&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: #000000\">This<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">function<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">checks<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">for<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">the<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">presence<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">of<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">the<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">WMI<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">Reliability<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">provider<\/span><span style=\"color: #808080\"> <br \/>&nbsp;&nbsp; <\/span><span style=\"color: #000000\">.Example<\/span><span style=\"color: #808080\"> <br \/>&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: #000000\">Test-ReliabilityProvider<\/span><span style=\"color: #808080\"> <br \/>&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: #000000\">Returns<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">true<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #0000ff\">if<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">reliability<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">exists<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">and<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">is<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">enabled<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">on<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">local<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">computer.<\/span><span style=\"color: #808080\">&nbsp; <br \/>&nbsp;&nbsp; <\/span><span style=\"color: #000000\">.Example<\/span><span style=\"color: #808080\"> <br \/>&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: #000000\">Test-ReliabilityProvider<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">-computer<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">berlin<\/span><span style=\"color: #808080\"> <br \/>&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: #000000\">Tests<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">for<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">presence<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">of<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">reliability<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">provider<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">on<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">remote<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">computer<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">named<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">berlin.<\/span><span style=\"color: #808080\"> <br \/>&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: #000000\">Returns<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">true<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #0000ff\">if<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">exists<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">and<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">is<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">enabled,<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">false<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">otherwise<\/span><span style=\"color: #808080\">&nbsp; <br \/>&nbsp;&nbsp; <\/span><span style=\"color: #000000\">.Parameter<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">Computer<\/span><span style=\"color: #808080\"> <br \/>&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: #000000\">Name<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">of<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">remote<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">computer<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">to<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">test<\/span><span style=\"color: #808080\"> <br \/>&nbsp;&nbsp; <\/span><span style=\"color: #000000\">.Inputs<\/span><span style=\"color: #808080\"> <br \/>&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: #000000\">[string]<\/span><span style=\"color: #808080\"> <br \/>&nbsp;&nbsp; <\/span><span style=\"color: #000000\">.Outputs<\/span><span style=\"color: #808080\"> <br \/>&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: #000000\">[boolean]<\/span><span style=\"color: #808080\"> <br \/>&nbsp;&nbsp; <\/span><span style=\"color: #000000\">.Notes<\/span><span style=\"color: #808080\"> <br \/>&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: #000000\">NAME:<\/span><span style=\"color: #808080\">&nbsp; <\/span><span style=\"color: #000000\">Test-ReliabilityProvider<\/span><span style=\"color: #808080\"> <br \/>&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: #000000\">AUTHOR:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">ed<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">wilson,<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">msft<\/span><span style=\"color: #808080\"> <br \/>&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: #000000\">LASTEDIT:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #800000\">09<\/span><span style=\"color: #000000\">\/<\/span><span style=\"color: #800000\">27<\/span><span style=\"color: #000000\">\/<\/span><span style=\"color: #800000\">2010<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #800000\">13<\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #800000\">59<\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #800000\">47<\/span><span style=\"color: #808080\"> <br \/>&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: #000000\">KEYWORDS:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">Operating<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">System,<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">Registry,<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">Scripting<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">Techniques,<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">WMI<\/span><span style=\"color: #808080\"> <br \/>&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: #000000\">HSG:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">HSG-10-06-10<\/span><span style=\"color: #808080\"> <br \/>&nbsp;&nbsp; <\/span><span style=\"color: #000000\">.Link<\/span><span style=\"color: #808080\"> <br \/>&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: #000000\">Http:\/\/www.ScriptingGuys.com<\/span><span style=\"color: #808080\"> <br \/>&nbsp;<\/span><span style=\"color: #0000ff\">#<\/span><span style=\"color: #000000\">Requires<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">-Version<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #800000\">2<\/span><span style=\"color: #000000\">.<\/span><span style=\"color: #800000\">0<\/span><span style=\"color: #808080\"> <br \/>&nbsp;<\/span><span style=\"color: #0000ff\">#<\/span><span style=\"color: #000000\">&gt;<\/span><span style=\"color: #808080\"> <br \/>&nbsp;<\/span><span style=\"color: #000000\">[cmdletBinding()]<\/span><span style=\"color: #808080\"> <br \/>&nbsp;<\/span><span style=\"color: #000000\">Param<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">([string]<\/span><span style=\"color: #2b91af\">$computer<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #0000ff\">=<\/span><span style=\"color: #808080\"> &#8220;.&#8221;<\/span><span style=\"color: #000000\">)<\/span><span style=\"color: #808080\"> <br \/>&nbsp;<\/span><span style=\"color: #2b91af\">$provider<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #0000ff\">=<\/span><span style=\"color: #808080\">&nbsp; <\/span><span style=\"color: #0000ff\">Get-WmiObject<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">-Class<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">__provider<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">-filter<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">`<\/span><span style=\"color: #808080\"> <br \/>&#8220;name = &#8216;ReliabilityMetricsProvider'&#8221; <\/span><span style=\"color: #000000\">-computername<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #2b91af\">$computer<\/span><span style=\"color: #808080\"> <br \/>&nbsp;<\/span><span style=\"color: #0000ff\">If<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #2b91af\">$provider<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #0000ff\">-ne<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #2b91af\">$null<\/span><span style=\"color: #000000\">)<\/span><span style=\"color: #808080\"> <br \/>&nbsp;&nbsp; <\/span><span style=\"color: #000000\">{<\/span><span style=\"color: #808080\"> <br \/>&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: #0000ff\">Write-Verbose<\/span><span style=\"color: #808080\"> &#8220;Reliability Provider found&#8221; <br \/>&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: #2b91af\">$hklm<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #0000ff\">=<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #800000\">2147483650<\/span><span style=\"color: #808080\"> <br \/>&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: #2b91af\">$key<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #0000ff\">=<\/span><span style=\"color: #808080\"> &#8220;SOFTWARE\\Policies\\Microsoft\\Windows\\Reliability Analysis\\WMI&#8221; <br \/>&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: #2b91af\">$value<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #0000ff\">=<\/span><span style=\"color: #808080\"> &#8220;WmiEnable&#8221; <br \/>&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: #2b91af\">$wmi<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #0000ff\">=<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">[wmiclass]<\/span><span style=\"color: #808080\">&#8220;\\\\$computer\\root\\default:stdRegProv&#8221; <br \/>&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: #0000ff\">if<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #2b91af\">$wmi<\/span><span style=\"color: #000000\">.GetDWORDValue(<\/span><span style=\"color: #2b91af\">$hklm<\/span><span style=\"color: #000000\">,<\/span><span style=\"color: #2b91af\">$key<\/span><span style=\"color: #000000\">,<\/span><span style=\"color: #2b91af\">$value<\/span><span style=\"color: #000000\">)).uValue<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #0000ff\">-eq<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #800000\">1<\/span><span style=\"color: #000000\">)<\/span><span style=\"color: #808080\">&nbsp; <br \/>&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: #000000\">{<\/span><span style=\"color: #808080\"> <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: #0000ff\">Write-Verbose<\/span><span style=\"color: #808080\"> &#8220;Reliability Provider enabled via Group Policy&#8221;&nbsp; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: #000000\">Return<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #2b91af\">$true<\/span><span style=\"color: #808080\">&nbsp; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: #000000\">}<\/span><span style=\"color: #808080\"> <br \/>&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: #0000ff\">Else<\/span><span style=\"color: #808080\">&nbsp; <br \/>&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: #000000\">{<\/span><span style=\"color: #808080\"> <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: #0000ff\">Write-verbose<\/span><span style=\"color: #808080\"> &#8220;Reliability Provider not enabled via Group Policy&#8221; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: #000000\">Return<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #2b91af\">$false<\/span><span style=\"color: #808080\">&nbsp; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: #000000\">}<\/span><span style=\"color: #808080\"> <br \/>&nbsp;&nbsp; <\/span><span style=\"color: #000000\">}<\/span><span style=\"color: #808080\"> <br \/>&nbsp;<\/span><span style=\"color: #0000ff\">Else<\/span><span style=\"color: #808080\">&nbsp; <br \/>&nbsp; <\/span><span style=\"color: #000000\">{<\/span><span style=\"color: #808080\"> <br \/>&nbsp;&nbsp; <\/span><span style=\"color: #0000ff\">Write-verbose<\/span><span style=\"color: #808080\"> &#8220;Reliability Provider does not exist&#8221;&nbsp; <br \/>&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: #000000\">Return<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #2b91af\">$false<\/span><span style=\"color: #808080\">&nbsp; <br \/>&nbsp;&nbsp; <\/span><span style=\"color: #000000\">}<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">}<\/span><span style=\"color: #808080\">&nbsp; <\/span><span style=\"color: #0000ff\">#<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">end<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">function<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">Test-ReliabilityProvider<\/span><span style=\"color: #808080\"> <br \/>&nbsp; <br \/>&nbsp;<\/span><span style=\"color: #0000ff\">#<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">***<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">Entry<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">Point<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">to<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">script<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">***<\/span><span style=\"color: #808080\"> <\/p>\n<p><\/span><span style=\"color: #0000ff\">#<\/span><span style=\"color: #000000\">Test-ReliabilityProvider<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">-computer<\/span><span style=\"color: #808080\"> &#8220;.&#8221; <\/span><span style=\"color: #000000\">-verbose<\/span> <\/p>\n<\/blockquote>\n<p>If you simply want to see if the WMI <b>Reliability<\/b> provider is installed and enabled on your computer, uncomment the last line in the script. The line to uncomment is shown here:<\/p>\n<blockquote>\n<div class=\"code\"><span style=\"color: #000000\">Test-ReliabilityProvider<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">-computer<\/span><span style=\"color: #808080\"> &#8220;.&#8221; <\/span><span style=\"color: #000000\">-verbose<\/span> <\/div>\n<\/blockquote>\n<p>When you run the script with the <b>verbose<\/b> parameter as seen above, the script will return information similar to that shown here:<\/p>\n<blockquote>\n<div class=\"code\"><span style=\"color: #0000ff\">PS<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">C:\\Users\\ed.NWTRADERS&gt;<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">C:\\data\\ScriptingGuys\\2010\\HSG_10_4_10\\Test-ReliabilityProvider.ps1<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">VERBOSE:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">Reliability<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">Provider<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">found<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">VERBOSE:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">Reliability<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">Provider<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">enabled<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">via<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #0000ff\">Group<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">Policy<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">True<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">___________________________________________________________________________________<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #0000ff\">PS<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">C:\\Users\\ed.NWTRADERS&gt;<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">C:\\data\\ScriptingGuys\\2010\\HSG_10_4_10\\Test-ReliabilityProvider.ps1<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">VERBOSE:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">Reliability<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">Provider<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">does<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">not<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">exist<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">False<\/span> <\/div>\n<\/blockquote>\n<p>If the function is called without the <b>&ndash;verbose<\/b> switch, the <b>Test-ReliabilityProvider<\/b> function returns either true or false. <\/p>\n<p>There are two ways to call the <b>Test-ReliabilityProvider<\/b> function (actually, there are at least three ways if you include adding it to a <a href=\"http:\/\/blogs.technet.com\/heyscriptingguy\/archive\/tags\/getting+started\/modules\/default.aspx\">module<\/a>). The first way is to have the function and the calling code in the same file. This is shown in Get-SortedReliabilityRecords_TestProvider_embeded.ps1. <\/p>\n<blockquote>\n<p><strong>Get-SortedReliabilityRecords_TestProvider_embeded.ps1<\/strong><\/p>\n<div class=\"code\"><span style=\"color: #000000\">Function<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">Test-ReliabilityProvider<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">{<\/span><span style=\"color: #808080\">&nbsp; <br \/>&nbsp; <\/span><span style=\"color: #000000\">&lt;<\/span><span style=\"color: #0000ff\">#<\/span><span style=\"color: #808080\"> <br \/>&nbsp;&nbsp; <\/span><span style=\"color: #000000\">.Synopsis<\/span><span style=\"color: #808080\"> <br \/>&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: #000000\">This<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">function<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">checks<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">for<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">the<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">presence<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">of<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">the<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">WMI<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">Reliability<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">provider<\/span><span style=\"color: #808080\"> <br \/>&nbsp;&nbsp; <\/span><span style=\"color: #000000\">.Description<\/span><span style=\"color: #808080\"> <br \/>&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: #000000\">This<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">function<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">checks<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">for<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">the<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">presence<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">of<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">the<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">WMI<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">Reliability<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">provider<\/span><span style=\"color: #808080\"> <br \/>&nbsp;&nbsp; <\/span><span style=\"color: #000000\">.Example<\/span><span style=\"color: #808080\"> <br \/>&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: #000000\">Test-ReliabilityProvider<\/span><span style=\"color: #808080\"> <br \/>&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: #000000\">Returns<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">true<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #0000ff\">if<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">reliability<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">exists<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">and<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">is<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">enabled<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">on<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">local<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">computer.<\/span><span style=\"color: #808080\">&nbsp; <br \/>&nbsp;&nbsp; <\/span><span style=\"color: #000000\">.Example<\/span><span style=\"color: #808080\"> <br \/>&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: #000000\">Test-ReliabilityProvider<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">-computer<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">berlin<\/span><span style=\"color: #808080\"> <br \/>&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: #000000\">Tests<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">for<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">presence<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">of<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">reliability<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">provider<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">on<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">remote<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">computer<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">named<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">berlin.<\/span><span style=\"color: #808080\"> <br \/>&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: #000000\">Returns<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">true<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #0000ff\">if<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">exists<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">and<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">is<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">enabled,<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">false<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">otherwise<\/span><span style=\"color: #808080\">&nbsp; <br \/>&nbsp;&nbsp; <\/span><span style=\"color: #000000\">.Parameter<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">Computer<\/span><span style=\"color: #808080\"> <br \/>&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: #000000\">Name<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">of<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">remote<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">computer<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">to<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">test<\/span><span style=\"color: #808080\"> <br \/>&nbsp;&nbsp; <\/span><span style=\"color: #000000\">.Inputs<\/span><span style=\"color: #808080\"> <br \/>&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: #000000\">[string]<\/span><span style=\"color: #808080\"> <br \/>&nbsp;&nbsp; <\/span><span style=\"color: #000000\">.Outputs<\/span><span style=\"color: #808080\"> <br \/>&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: #000000\">[boolean]<\/span><span style=\"color: #808080\"> <br \/>&nbsp;&nbsp; <\/span><span style=\"color: #000000\">.Notes<\/span><span style=\"color: #808080\"> <br \/>&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: #000000\">NAME:<\/span><span style=\"color: #808080\">&nbsp; <\/span><span style=\"color: #000000\">Test-ReliabilityProvider<\/span><span style=\"color: #808080\"> <br \/>&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: #000000\">AUTHOR:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">ed<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">wilson,<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">msft<\/span><span style=\"color: #808080\"> <br \/>&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: #000000\">LASTEDIT:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #800000\">09<\/span><span style=\"color: #000000\">\/<\/span><span style=\"color: #800000\">27<\/span><span style=\"color: #000000\">\/<\/span><span style=\"color: #800000\">2010<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #800000\">13<\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #800000\">59<\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #800000\">47<\/span><span style=\"color: #808080\"> <br \/>&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: #000000\">KEYWORDS:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">Operating<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">System,<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">Registry,<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">Scripting<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">Techniques,<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">WMI<\/span><span style=\"color: #808080\"> <br \/>&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: #000000\">HSG:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">HSG-10-06-10<\/span><span style=\"color: #808080\"> <br \/>&nbsp;&nbsp; <\/span><span style=\"color: #000000\">.Link<\/span><span style=\"color: #808080\"> <br \/>&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: #000000\">Http:\/\/www.ScriptingGuys.com<\/span><span style=\"color: #808080\"> <br \/>&nbsp;<\/span><span style=\"color: #0000ff\">#<\/span><span style=\"color: #000000\">Requires<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">-Version<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #800000\">2<\/span><span style=\"color: #000000\">.<\/span><span style=\"color: #800000\">0<\/span><span style=\"color: #808080\"> <br \/>&nbsp;<\/span><span style=\"color: #0000ff\">#<\/span><span style=\"color: #000000\">&gt;<\/span><span style=\"color: #808080\"> <br \/>&nbsp;<\/span><span style=\"color: #000000\">[cmdletBinding()]<\/span><span style=\"color: #808080\"> <br \/>&nbsp;<\/span><span style=\"color: #000000\">Param<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">([string]<\/span><span style=\"color: #2b91af\">$computer<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #0000ff\">=<\/span><span style=\"color: #808080\"> &#8220;.&#8221;<\/span><span style=\"color: #000000\">)<\/span><span style=\"color: #808080\"> <br \/>&nbsp;<\/span><span style=\"color: #2b91af\">$provider<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #0000ff\">=<\/span><span style=\"color: #808080\">&nbsp; <\/span><span style=\"color: #0000ff\">Get-WmiObject<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">-Class<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">__provider<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">-filter<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">`<\/span><span style=\"color: #808080\"> <br \/>&#8220;name = &#8216;ReliabilityMetricsProvider'&#8221; <\/span><span style=\"color: #000000\">-computername<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #2b91af\">$computer<\/span><span style=\"color: #808080\"> <br \/>&nbsp;<\/span><span style=\"color: #0000ff\">If<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #2b91af\">$provider<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #0000ff\">-ne<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #2b91af\">$null<\/span><span style=\"color: #000000\">)<\/span><span style=\"color: #808080\"> <br \/>&nbsp;&nbsp; <\/span><span style=\"color: #000000\">{<\/span><span style=\"color: #808080\"> <br \/>&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: #0000ff\">Write-Verbose<\/span><span style=\"color: #808080\"> &#8220;Reliability Provider found&#8221; <br \/>&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: #2b91af\">$hklm<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #0000ff\">=<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #800000\">2147483650<\/span><span style=\"color: #808080\"> <br \/>&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: #2b91af\">$key<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #0000ff\">=<\/span><span style=\"color: #808080\"> &#8220;SOFTWARE\\Policies\\Microsoft\\Windows\\Reliability Analysis\\WMI&#8221; <br \/>&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: #2b91af\">$value<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #0000ff\">=<\/span><span style=\"color: #808080\"> &#8220;WmiEnable&#8221; <br \/>&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: #2b91af\">$wmi<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #0000ff\">=<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">[wmiclass]<\/span><span style=\"color: #808080\">&#8220;\\\\$computer\\root\\default:stdRegProv&#8221; <br \/>&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: #0000ff\">if<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #2b91af\">$wmi<\/span><span style=\"color: #000000\">.GetDWORDValue(<\/span><span style=\"color: #2b91af\">$hklm<\/span><span style=\"color: #000000\">,<\/span><span style=\"color: #2b91af\">$key<\/span><span style=\"color: #000000\">,<\/span><span style=\"color: #2b91af\">$value<\/span><span style=\"color: #000000\">)).uValue<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #0000ff\">-eq<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #800000\">1<\/span><span style=\"color: #000000\">)<\/span><span style=\"color: #808080\">&nbsp; <br \/>&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: #000000\">{<\/span><span style=\"color: #808080\"> <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: #0000ff\">Write-Verbose<\/span><span style=\"color: #808080\"> &#8220;Reliability Provider enabled via Group Policy&#8221;&nbsp; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: #000000\">Return<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #2b91af\">$true<\/span><span style=\"color: #808080\">&nbsp; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: #000000\">}<\/span><span style=\"color: #808080\"> <br \/>&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: #0000ff\">Else<\/span><span style=\"color: #808080\">&nbsp; <br \/>&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: #000000\">{<\/span><span style=\"color: #808080\"> <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: #0000ff\">Write-verbose<\/span><span style=\"color: #808080\"> &#8220;Reliability Provider not enabled via Group Policy&#8221; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: #000000\">Return<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #2b91af\">$false<\/span><span style=\"color: #808080\">&nbsp; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: #000000\">}<\/span><span style=\"color: #808080\"> <br \/>&nbsp;&nbsp; <\/span><span style=\"color: #000000\">}<\/span><span style=\"color: #808080\"> <br \/>&nbsp;<\/span><span style=\"color: #0000ff\">Else<\/span><span style=\"color: #808080\">&nbsp; <br \/>&nbsp; <\/span><span style=\"color: #000000\">{<\/span><span style=\"color: #808080\"> <br \/>&nbsp;&nbsp; <\/span><span style=\"color: #0000ff\">Write-verbose<\/span><span style=\"color: #808080\"> &#8220;Reliability Provider does not exist&#8221;&nbsp; <br \/>&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: #000000\">Return<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #2b91af\">$false<\/span><span style=\"color: #808080\">&nbsp; <br \/>&nbsp;&nbsp; <\/span><span style=\"color: #000000\">}<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">}<\/span><span style=\"color: #808080\">&nbsp; <\/span><span style=\"color: #0000ff\">#<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">end<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">function<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">Test-ReliabilityProvider<\/span><span style=\"color: #808080\"> <\/p>\n<p><\/span><span style=\"color: #000000\">Function<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">Get-SortedReliabilityRecords<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">{<\/span><span style=\"color: #808080\"> <br \/>&nbsp;<\/span><span style=\"color: #000000\">Param<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">([string]<\/span><span style=\"color: #2b91af\">$computer<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #0000ff\">=<\/span><span style=\"color: #808080\"> &#8220;.&#8221;<\/span><span style=\"color: #000000\">)<\/span><span style=\"color: #808080\"> <br \/>&nbsp;<\/span><span style=\"color: #0000ff\">Get-WmiObject<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">-Class<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">win32_reliabilityRecords<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">-ComputerName<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #2b91af\">$computer<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">|<\/span><span style=\"color: #808080\"> <br \/>&nbsp;<\/span><span style=\"color: #0000ff\">Group-Object<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">-Property<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">sourcename,<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">eventidentifier<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">-NoElement<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">|<\/span><span style=\"color: #808080\"> <br \/>&nbsp;<\/span><span style=\"color: #0000ff\">Sort-Object<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">-Descending<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">count<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">|<\/span><span style=\"color: #808080\"> <br \/>&nbsp;<\/span><span style=\"color: #0000ff\">Format-Table<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">-AutoSize<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">-Property<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">count,<\/span><span style=\"color: #808080\">&nbsp; <br \/>&nbsp; <\/span><span style=\"color: #000000\">@{Label<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #0000ff\">=<\/span><span style=\"color: #808080\"> &#8220;Source, EventID&#8221;<\/span><span style=\"color: #0000ff\">;<\/span><span style=\"color: #000000\">Expression<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #0000ff\">=<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">{<\/span><span style=\"color: #2b91af\">$_<\/span><span style=\"color: #000000\">.name}<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">}<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">}<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #0000ff\">#<\/span><span style=\"color: #000000\">end<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">function<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">Get-SortedReliabilityRecords<\/span><span style=\"color: #808080\"> <\/p>\n<p><\/span><span style=\"color: #0000ff\">#<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">***<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">Entry<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">Point<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">to<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">Script<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">***<\/span><span style=\"color: #808080\"> <\/p>\n<p><\/span><span style=\"color: #2b91af\">$computer<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #0000ff\">=<\/span><span style=\"color: #808080\"> &#8220;.&#8221; <br \/><\/span><span style=\"color: #0000ff\">if<\/span><span style=\"color: #000000\">(Test-ReliabilityProvider<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">-computer<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #2b91af\">$computer<\/span><span style=\"color: #000000\">)<\/span><span style=\"color: #808080\"> <br \/>&nbsp;&nbsp; <\/span><span style=\"color: #000000\">{<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">Get-SortedReliabilityRecords<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">-computer<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #2b91af\">$computer<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">}<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #0000ff\">else<\/span><span style=\"color: #808080\">&nbsp; <br \/>&nbsp; <\/span><span style=\"color: #000000\">{<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #0000ff\">write-host<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">-ForegroundColor<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">red<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">`<\/span><span style=\"color: #808080\"> <br \/>&nbsp;&nbsp;&nbsp; &#8220;WMI Reliability Provider either does not exist <br \/>&nbsp;&nbsp;&nbsp; or is not enabled via Group Policy&#8221; <\/span><span style=\"color: #000000\">}<\/span> <\/div>\n<\/blockquote>\n<p>The function I am interested in running is the <b>Get-SortedReliabilityRecords<\/b> function that will display an output such as that shown in the following image.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/6114.HSG-10-07-10-01_15D0F136.jpg\"><img decoding=\"async\" height=\"474\" width=\"604\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/2313.HSG-10-07-10-01_thumb_1347BF78.jpg\" alt=\"Image of output from Get-SortedReliabilityRecords function\" border=\"0\" title=\"Image of output from Get-SortedReliabilityRecords function\" style=\"border-right: 0px;padding-right: 0px;border-top: 0px;padding-left: 0px;border-left: 0px;padding-top: 0px;border-bottom: 0px\" \/><\/a><\/p>\n<p>To ensure that the script does not fail abnormally, the <b>Test-ReliabilityProvider<\/b> function is called. If the <b>Test-ReliabilityProvider<\/b> function returns <b>$true<\/b>, the <b>Get-SortedReliabilityRecords<\/b> function is called. If it does not return true, a message is displayed on the Windows PowerShell console. This portion of the code is shown here: <\/p>\n<blockquote>\n<div class=\"code\"><span style=\"color: #0000ff\">#<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">***<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">Entry<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">Point<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">to<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">Script<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">***<\/span><span style=\"color: #808080\"> <\/p>\n<p><\/span><span style=\"color: #2b91af\">$computer<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #0000ff\">=<\/span><span style=\"color: #808080\"> &#8220;.&#8221; <br \/><\/span><span style=\"color: #0000ff\">if<\/span><span style=\"color: #000000\">(Test-ReliabilityProvider<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">-computer<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #2b91af\">$computer<\/span><span style=\"color: #000000\">)<\/span><span style=\"color: #808080\"> <br \/>&nbsp;&nbsp; <\/span><span style=\"color: #000000\">{<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">Get-SortedReliabilityRecords<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">-computer<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #2b91af\">$computer<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">}<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #0000ff\">else<\/span><span style=\"color: #808080\">&nbsp; <br \/>&nbsp; <\/span><span style=\"color: #000000\">{<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #0000ff\">write-host<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">-ForegroundColor<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">red<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">`<\/span><span style=\"color: #808080\"> <br \/>&nbsp;&nbsp;&nbsp; &#8220;WMI Reliability Provider either does not exist <br \/>&nbsp;&nbsp;&nbsp; or is not enabled via Group Policy&#8221; <\/span><span style=\"color: #000000\">}<\/span> <\/div>\n<\/blockquote>\n<p>The advantage of this approach is that the script is completely self-contained. There are no external dependencies that need to be tracked. The disadvantage is that the script is more than 80 lines long. For some scripters, this becomes an issue; for others, the advantage of portability overrides the three seconds it took to copy and paste the function from the Test-ReliabilityProvider.ps1 script into the Get-SortedReliabilityRecords_TestProvider_embeded.ps1 script. <\/p>\n<p>By dot-sourcing the <b>Test-ReliabilityProvider<\/b> function from the Test-ReliabilityProvider.ps1 script, the function is made available in the Get-SortedReliabilityRecords_TestProvider_DotSource.ps1 script without the need to copy 80 lines of code into the new script. The only requirement to be able to dot-source the function from the script is access to the Windows PowerShell script file. In this example, the source file is stored in folder c:\\fso, as shown in the following image. <\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/0753.HSG-10-07-10-02_79738948.jpg\"><img decoding=\"async\" height=\"349\" width=\"604\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/6457.HSG-10-07-10-02_thumb_62D13B01.jpg\" alt=\"Image of source file stored in folder c:\\fso\" border=\"0\" title=\"Image of source file stored in folder c:\\fso\" style=\"border-right: 0px;padding-right: 0px;border-top: 0px;padding-left: 0px;border-left: 0px;padding-top: 0px;border-bottom: 0px\" \/><\/a><\/p>\n<p>The code required to dot-source the script is a period, a space, and the path to the file. This is shown here:<\/p>\n<blockquote>\n<div class=\"code\"><span style=\"color: #000000\">.<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">C:\\fso\\Test-ReliabilityProvider.ps1<\/span> <\/div>\n<\/blockquote>\n<p>The remainder of the entry point to the script is exactly the same as with the embedded function. The complete Get-SortedReliabilityRecords_TestProvider_DotSource.ps1 script is shown here. <\/p>\n<blockquote>\n<p><strong>Get-SortedReliabilityRecords_TestProvider_DotSource.ps1<\/strong><\/p>\n<p><span style=\"color: #000000\">Function<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">Get-SortedReliabilityRecords<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">{<\/span><span style=\"color: #808080\"> <br \/>&nbsp;<\/span><span style=\"color: #000000\">Param<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">([string]<\/span><span style=\"color: #2b91af\">$computer<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #0000ff\">=<\/span><span style=\"color: #808080\"> &#8220;.&#8221;<\/span><span style=\"color: #000000\">)<\/span><span style=\"color: #808080\"> <br \/>&nbsp;<\/span><span style=\"color: #0000ff\">Get-WmiObject<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">-Class<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">win32_reliabilityRecords<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">-ComputerName<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #2b91af\">$computer<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">|<\/span><span style=\"color: #808080\"> <br \/>&nbsp;<\/span><span style=\"color: #0000ff\">Group-Object<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">-Property<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">sourcename,<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">eventidentifier<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">-NoElement<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">|<\/span><span style=\"color: #808080\"> <br \/>&nbsp;<\/span><span style=\"color: #0000ff\">Sort-Object<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">-Descending<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">count<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">|<\/span><span style=\"color: #808080\"> <br \/>&nbsp;<\/span><span style=\"color: #0000ff\">Format-Table<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">-AutoSize<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">-Property<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">count,<\/span><span style=\"color: #808080\">&nbsp; <br \/>&nbsp; <\/span><span style=\"color: #000000\">@{Label<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #0000ff\">=<\/span><span style=\"color: #808080\"> &#8220;Source, EventID&#8221;<\/span><span style=\"color: #0000ff\">;<\/span><span style=\"color: #000000\">Expression<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #0000ff\">=<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">{<\/span><span style=\"color: #2b91af\">$_<\/span><span style=\"color: #000000\">.name}<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">}<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">}<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #0000ff\">#<\/span><span style=\"color: #000000\">end<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">function<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">Get-SortedReliabilityRecords<\/span><span style=\"color: #808080\"> <\/p>\n<p><\/span><span style=\"color: #0000ff\">#<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">***<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">Entry<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">Point<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">to<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">Script<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">***<\/span><span style=\"color: #808080\"> <\/p>\n<p><\/span><span style=\"color: #000000\">.<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">C:\\fso\\Test-ReliabilityProvider.ps1<\/span><span style=\"color: #808080\"> <\/p>\n<p><\/span><span style=\"color: #2b91af\">$computer<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #0000ff\">=<\/span><span style=\"color: #808080\"> &#8220;.&#8221; <br \/><\/span><span style=\"color: #0000ff\">if<\/span><span style=\"color: #000000\">(Test-ReliabilityProvider<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">-computer<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #2b91af\">$computer<\/span><span style=\"color: #000000\">)<\/span><span style=\"color: #808080\"> <br \/>&nbsp;&nbsp; <\/span><span style=\"color: #000000\">{<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">Get-SortedReliabilityRecords<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">-computer<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #2b91af\">$computer<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">}<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #0000ff\">else<\/span><span style=\"color: #808080\">&nbsp; <br \/>&nbsp; <\/span><span style=\"color: #000000\">{<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #0000ff\">write-host<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">-ForegroundColor<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">red<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">`<\/span><span style=\"color: #808080\"> <br \/>&nbsp;&nbsp;&nbsp; &#8220;WMI Reliability Provider either does not exist <br \/>&nbsp;&nbsp;&nbsp; or is not enabled via Group Policy&#8221; <\/span><span style=\"color: #000000\">}<\/span> <\/p>\n<\/blockquote>\n<p>Of course, if you can dot-source one function, you can dot-source two functions. When dot-sourcing functions in a script, you may wish to check to see if the file actually exists prior to attempting to call the code. To do this, use the <a href=\"http:\/\/technet.microsoft.com\/en-us\/library\/dd315298.aspx\">Test-Path<\/a> cmdlet. If the file exists, you go ahead and include the function in your script by dot-sourcing it. If the file does not exist, the script should exit gracefully while displaying a useful message. This approach is illustrated in the DotSourceReliabilityProviderAndSortRecords.ps1 script shown here. <\/p>\n<blockquote>\n<p><strong>DotSourceReliabilityProviderAndSortRecords.ps1<\/strong><\/p>\n<p><span style=\"color: #2b91af\">$TestReliabilityProvider<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #0000ff\">=<\/span><span style=\"color: #808080\"> &#8220;C:\\fso\\Test-ReliabilityProvider.ps1&#8221; <br \/><\/span><span style=\"color: #2b91af\">$SortedReliabilityRecord<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #0000ff\">=<\/span><span style=\"color: #808080\"> &#8220;C:\\fso\\Get-SortedReliabilityRecords_Function.ps1&#8221; <br \/><\/span><span style=\"color: #0000ff\">If<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #0000ff\">test-path<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">-path<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #2b91af\">$TestReliabilityProvider<\/span><span style=\"color: #000000\">)<\/span><span style=\"color: #808080\"> <br \/>&nbsp;<\/span><span style=\"color: #000000\">{<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">.<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #2b91af\">$TestReliabilityProvider<\/span><span style=\"color: #000000\">}<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #0000ff\">Else<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">{<\/span><span style=\"color: #808080\"> &#8220;$TestReliabilityProvider not found&#8221; <\/span><span style=\"color: #0000ff\">;<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">exit<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">}<\/span><span style=\"color: #808080\"> <\/p>\n<p><\/span><span style=\"color: #0000ff\">If<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #0000ff\">Test-Path<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">-Path<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #2b91af\">$SortedReliabilityRecord<\/span><span style=\"color: #000000\">)<\/span><span style=\"color: #808080\"> <br \/>&nbsp;<\/span><span style=\"color: #000000\">{<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">.<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #2b91af\">$SortedReliabilityRecord<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">}<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #0000ff\">else<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">{<\/span><span style=\"color: #808080\">&#8220;$SortedReliabilityRecord not found&#8221; <\/span><span style=\"color: #0000ff\">;<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">exit<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">}<\/span><span style=\"color: #808080\"> <\/p>\n<p><\/span><span style=\"color: #2b91af\">$computer<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #0000ff\">=<\/span><span style=\"color: #808080\"> &#8220;.&#8221; <br \/><\/span><span style=\"color: #0000ff\">if<\/span><span style=\"color: #000000\">(Test-ReliabilityProvider<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">-computer<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #2b91af\">$computer<\/span><span style=\"color: #000000\">)<\/span><span style=\"color: #808080\"> <br \/>&nbsp;&nbsp; <\/span><span style=\"color: #000000\">{<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">Get-SortedReliabilityRecords<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">-computer<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #2b91af\">$computer<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">}<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #0000ff\">else<\/span><span style=\"color: #808080\">&nbsp; <br \/>&nbsp; <\/span><span style=\"color: #000000\">{<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #0000ff\">write-host<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">-ForegroundColor<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">red<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">`<\/span><span style=\"color: #808080\"> <br \/>&nbsp;&nbsp;&nbsp; &#8220;WMI Reliability Provider either does not exist <br \/>&nbsp;&nbsp;&nbsp; or is not enabled via Group Policy&#8221; <\/span><span style=\"color: #000000\">}<\/span> <\/p>\n<\/blockquote>\n<p>It would actually be simpler to place the two functions inside a module and install the module than to do all the path testing and exiting. For more information about creating and installing modules, see the Hey, Scripting Guy! <a href=\"http:\/\/blogs.technet.com\/b\/heyscriptingguy\/archive\/tags\/windows+powershell\/getting+started\/modules\/\">Getting Started with Modules<\/a> series of posts. <\/p>\n<p>&nbsp;<\/p>\n<p>TE, that is all there is to using Windows PowerShell and the WMI reliability classes. Join us tomorrow as we conclude Reliability Week when we talk about parsing reliability output.<\/p>\n<p>We invite you to follow us on <a href=\"http:\/\/bit.ly\/scriptingguystwitter\">Twitter<\/a> and <a href=\"http:\/\/bit.ly\/scriptingguysfacebook\">Facebook<\/a>. If you have any questions, send email to us at <a href=\"mailto:scripter@microsoft.com\">scripter@microsoft.com<\/a>, or post your questions on the <a href=\"http:\/\/social.technet.microsoft.com\/Forums\/en\/ITCG\/threads\/\">Official Scripting Guys Forum<\/a>. See you tomorrow. Until then, peace.<\/p>\n<p>&nbsp;<\/p>\n<p><b>Ed Wilson and Craig Liebendorfer, Scripting Guys<\/b><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Summary: The Microsoft Scripting Guys describe how to reuse Windows PowerShell code to simplify script writing and retrieve reliability information. &nbsp; Hey, Scripting Guy! I really enjoy reading your stuff. It is generally both fun and informative. The thing I appreciate the most is that your writing does not read like standard product documentation. I [&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":[31,60,26,3,4,45,6],"class_list":["post-16891","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-operating-system","tag-performance","tag-registry","tag-scripting-guy","tag-scripting-techniques","tag-windows-powershell","tag-wmi"],"acf":[],"blog_post_summary":"<p>Summary: The Microsoft Scripting Guys describe how to reuse Windows PowerShell code to simplify script writing and retrieve reliability information. &nbsp; Hey, Scripting Guy! I really enjoy reading your stuff. It is generally both fun and informative. The thing I appreciate the most is that your writing does not read like standard product documentation. I [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/16891","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=16891"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/16891\/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=16891"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=16891"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=16891"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}