<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Get-WmiCustom (aka: Get-WMIObject with timeout!)</title>
	<atom:link href="http://www.muscetta.com/2009/05/27/get-wmicustom/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.muscetta.com/2009/05/27/get-wmicustom/</link>
	<description>Superior Dedication - If you try hard enough, you might even get it to work.</description>
	<lastBuildDate>Sat, 24 Sep 2011 17:52:48 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: Daniele Muscetta</title>
		<link>http://www.muscetta.com/2009/05/27/get-wmicustom/comment-page-1/#comment-29201</link>
		<dc:creator>Daniele Muscetta</dc:creator>
		<pubDate>Sat, 24 Sep 2011 17:52:48 +0000</pubDate>
		<guid isPermaLink="false">http://www.muscetta.com/?p=443#comment-29201</guid>
		<description>Kelly, I am not sure, I would have to see/test your script myself to try to understand what is happening there....</description>
		<content:encoded><![CDATA[<p>Kelly, I am not sure, I would have to see/test your script myself to try to understand what is happening there&#8230;.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kelly S</title>
		<link>http://www.muscetta.com/2009/05/27/get-wmicustom/comment-page-1/#comment-29200</link>
		<dc:creator>Kelly S</dc:creator>
		<pubDate>Wed, 21 Sep 2011 21:38:33 +0000</pubDate>
		<guid isPermaLink="false">http://www.muscetta.com/?p=443#comment-29200</guid>
		<description>Trying to use your function but have run into a very strange behavior... I&#039;m pulling server names from a DB then query them for OS and compare that to what the DB has already.  Problem is... the results returned come back with the exact same OS from wmi for all servers. Change back to using get-wmiobject and problem disappears... 

Any ideas?</description>
		<content:encoded><![CDATA[<p>Trying to use your function but have run into a very strange behavior&#8230; I&#039;m pulling server names from a DB then query them for OS and compare that to what the DB has already.  Problem is&#8230; the results returned come back with the exact same OS from wmi for all servers. Change back to using get-wmiobject and problem disappears&#8230; </p>
<p>Any ideas?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Daniele Muscetta</title>
		<link>http://www.muscetta.com/2009/05/27/get-wmicustom/comment-page-1/#comment-29172</link>
		<dc:creator>Daniele Muscetta</dc:creator>
		<pubDate>Wed, 03 Nov 2010 06:10:31 +0000</pubDate>
		<guid isPermaLink="false">http://www.muscetta.com/?p=443#comment-29172</guid>
		<description>Why did you place the trap that high? in my example it is just wrapping the $searcher.get() --&gt; which is where the timeout would occur.</description>
		<content:encoded><![CDATA[<p>Why did you place the trap that high? in my example it is just wrapping the $searcher.get() &#8211;&gt; which is where the timeout would occur.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sam</title>
		<link>http://www.muscetta.com/2009/05/27/get-wmicustom/comment-page-1/#comment-29171</link>
		<dc:creator>Sam</dc:creator>
		<pubDate>Tue, 02 Nov 2010 19:47:27 +0000</pubDate>
		<guid isPermaLink="false">http://www.muscetta.com/?p=443#comment-29171</guid>
		<description>This code is killing me. I have a system that times out, but can&#039;t find a way to trap the error so that I can make further decisions on it... Seems like PowerShell doesn&#039;t always stop processing lines during the pause. What am I missing in this code?

trap {$_;$Script:WMIWorks = $False; Write-Host &quot;Value of WMITest: $WMIWorks&quot;;continue} 
$ComputerName = &quot;&quot;
 $Error.Clear()
 $ConnectionOptions = new-object System.Management.ConnectionOptions
 $EnumerationOptions = new-object System.Management.EnumerationOptions 
 $timeoutseconds = new-timespan -seconds 10
 $EnumerationOptions.set_timeout($timeoutseconds)
 $assembledpath = &quot;\\&quot; + $computername + &quot;\root\cimv2&quot;
 $Scope = new-object System.Management.ManagementScope $assembledpath, $ConnectionOptions
 $Scope.Connect()
 $querystring = &quot;SELECT * FROM Win32_NetworkAdapterConfiguration&quot;
 $query = new-object System.Management.ObjectQuery $querystring
 $searcher = new-object System.Management.ManagementObjectSearcher
 $searcher.set_options($EnumerationOptions)
 $searcher.Query = $querystring
 $searcher.Scope = $Scope 
 $WMIWorks = $True
 $AdapterDetails = $Searcher.Get()
#IF the WMI call times out, this IF statement and ELSE statement get ignored. I don&#039;t know why. 
If ($WMIWorks -eq $False) 
  {
  Write-Host &quot;We will do lots of things differently&quot;
  # We might do a DNS lookup
  # We might ping the host
  # We may change where where we write the out put to
  # We might write this to a different spread sheet in excel and color it red
  }
 Else 
  {
  $AdapterDetails
  Write-Host &quot;We will do things as planned&quot;
  #Write the out put to Excel and color code it green
  }
 Write-Host &quot;Value of WMI Test is: $WMIWorks&quot;</description>
		<content:encoded><![CDATA[<p>This code is killing me. I have a system that times out, but can&#039;t find a way to trap the error so that I can make further decisions on it&#8230; Seems like PowerShell doesn&#039;t always stop processing lines during the pause. What am I missing in this code?</p>
<p>trap {$_;$Script:WMIWorks = $False; Write-Host &#034;Value of WMITest: $WMIWorks&#034;;continue}<br />
$ComputerName = &#034;&#034;<br />
 $Error.Clear()<br />
 $ConnectionOptions = new-object System.Management.ConnectionOptions<br />
 $EnumerationOptions = new-object System.Management.EnumerationOptions<br />
 $timeoutseconds = new-timespan -seconds 10<br />
 $EnumerationOptions.set_timeout($timeoutseconds)<br />
 $assembledpath = &#034;\\&#034; + $computername + &#034;\root\cimv2&#034;<br />
 $Scope = new-object System.Management.ManagementScope $assembledpath, $ConnectionOptions<br />
 $Scope.Connect()<br />
 $querystring = &#034;SELECT * FROM Win32_NetworkAdapterConfiguration&#034;<br />
 $query = new-object System.Management.ObjectQuery $querystring<br />
 $searcher = new-object System.Management.ManagementObjectSearcher<br />
 $searcher.set_options($EnumerationOptions)<br />
 $searcher.Query = $querystring<br />
 $searcher.Scope = $Scope<br />
 $WMIWorks = $True<br />
 $AdapterDetails = $Searcher.Get()<br />
#IF the WMI call times out, this IF statement and ELSE statement get ignored. I don&#039;t know why.<br />
If ($WMIWorks -eq $False)<br />
  {<br />
  Write-Host &#034;We will do lots of things differently&#034;<br />
  # We might do a DNS lookup<br />
  # We might ping the host<br />
  # We may change where where we write the out put to<br />
  # We might write this to a different spread sheet in excel and color it red<br />
  }<br />
 Else<br />
  {<br />
  $AdapterDetails<br />
  Write-Host &#034;We will do things as planned&#034;<br />
  #Write the out put to Excel and color code it green<br />
  }<br />
 Write-Host &#034;Value of WMI Test is: $WMIWorks&#034;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Daniele Muscetta</title>
		<link>http://www.muscetta.com/2009/05/27/get-wmicustom/comment-page-1/#comment-29168</link>
		<dc:creator>Daniele Muscetta</dc:creator>
		<pubDate>Tue, 31 Aug 2010 19:40:45 +0000</pubDate>
		<guid isPermaLink="false">http://www.muscetta.com/?p=443#comment-29168</guid>
		<description>Sweet addition, thanks.</description>
		<content:encoded><![CDATA[<p>Sweet addition, thanks.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kevin</title>
		<link>http://www.muscetta.com/2009/05/27/get-wmicustom/comment-page-1/#comment-29167</link>
		<dc:creator>Kevin</dc:creator>
		<pubDate>Tue, 31 Aug 2010 15:55:45 +0000</pubDate>
		<guid isPermaLink="false">http://www.muscetta.com/?p=443#comment-29167</guid>
		<description>Thanks for this post, it is very frustrating that most powershell cmdlets do not have a timeout value. I made a modification to your function to add the ability to add the -filter attribute, just two changes were needed. I added - [string]$filter - to the variable definition line and made this modification to the $querystring variable

$querystring = &quot;SELECT * FROM &quot; + $class + $(if ($filter) {&quot; WHERE $filter&quot;})</description>
		<content:encoded><![CDATA[<p>Thanks for this post, it is very frustrating that most powershell cmdlets do not have a timeout value. I made a modification to your function to add the ability to add the -filter attribute, just two changes were needed. I added &#8211; [string]$filter &#8211; to the variable definition line and made this modification to the $querystring variable</p>
<p>$querystring = &#034;SELECT * FROM &#034; + $class + $(if ($filter) {&#034; WHERE $filter&#034;})</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Daniele Muscetta</title>
		<link>http://www.muscetta.com/2009/05/27/get-wmicustom/comment-page-1/#comment-29155</link>
		<dc:creator>Daniele Muscetta</dc:creator>
		<pubDate>Thu, 17 Dec 2009 18:15:07 +0000</pubDate>
		<guid isPermaLink="false">http://www.muscetta.com/?p=443#comment-29155</guid>
		<description>I should see how your CSV file looks like... why not just a simple TXT file, with one machine per row?

foreach ($comp in (get-content c:\computers.txt))
{
   get-wmicustom -class win32_logicaldisk -namespace &quot;root/cimv2&quot; - computername $comp
}</description>
		<content:encoded><![CDATA[<p>I should see how your CSV file looks like&#8230; why not just a simple TXT file, with one machine per row?</p>
<p>foreach ($comp in (get-content c:\computers.txt))<br />
{<br />
   get-wmicustom -class win32_logicaldisk -namespace &#034;root/cimv2&#034; &#8211; computername $comp<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: D</title>
		<link>http://www.muscetta.com/2009/05/27/get-wmicustom/comment-page-1/#comment-29154</link>
		<dc:creator>D</dc:creator>
		<pubDate>Tue, 08 Dec 2009 17:55:26 +0000</pubDate>
		<guid isPermaLink="false">http://www.muscetta.com/?p=443#comment-29154</guid>
		<description>Hi there,

This is cool and seems to work well for single queries. As a Powershell novice I&#039;m trying to figure out how I can make it work in a script that reads computer names from a CSV file and queries the space on the C: partition via your function (which I modified quickly to add a filter, which does work). I tried the following code but it returns errors like &#039;Exception calling &quot;Connect&quot; with &quot;0&quot; argument(s): &quot;The RPC server is unavailable.&quot;&#039; I guess this means the computer names aren&#039;t being read in properly. Any idea how to make this work? Thanks so much!


Function Get-WmiCustom([string]$computername,[string]$namespace,[string]$class,[int]$timeout=15)
{
$ConnectionOptions = new-object System.Management.ConnectionOptions
$EnumerationOptions = new-object System.Management.EnumerationOptions

$timeoutseconds = new-timespan -seconds $timeout
$EnumerationOptions.set_timeout($timeoutseconds)

$assembledpath = &quot;\\&quot; + $computername + &quot;\&quot; + $namespace
#write-host $assembledpath -foregroundcolor yellow

$Scope = new-object System.Management.ManagementScope $assembledpath, $ConnectionOptions
$Scope.Connect()

$querystring = &quot;SELECT * FROM &quot; + $class + &quot; where DriveType=3 AND DeviceID=&#039;C:&#039;&quot;
#write-host $querystring

$query = new-object System.Management.ObjectQuery $querystring
$searcher = new-object System.Management.ManagementObjectSearcher
$searcher.set_options($EnumerationOptions)
$searcher.Query = $querystring
$searcher.Scope = $Scope

trap { $_ } $result = $searcher.get()

return $result
}

$csv = &quot;machines.csv&quot;

$import = Import-CSV $csv

$import &#124; foreach {
get-wmicustom -class win32_logicaldisk -namespace &quot;root\cimv2&quot; -computername {$_.hostname} &#124; Select SystemName,DeviceID,VolumeName,@{Name=&quot;size(GB)&quot;;Expression={&quot;{0:N1}&quot; -f($_.size/1gb)}},@{Name=&quot;freespace(GB)&quot;;Expression={&quot;{0:N1}&quot; -f($_.freespace/1gb)}}
}</description>
		<content:encoded><![CDATA[<p>Hi there,</p>
<p>This is cool and seems to work well for single queries. As a Powershell novice I&#039;m trying to figure out how I can make it work in a script that reads computer names from a CSV file and queries the space on the C: partition via your function (which I modified quickly to add a filter, which does work). I tried the following code but it returns errors like &#039;Exception calling &#034;Connect&#034; with &#034;0&#034; argument(s): &#034;The RPC server is unavailable.&#034;&#039; I guess this means the computer names aren&#039;t being read in properly. Any idea how to make this work? Thanks so much!</p>
<p>Function Get-WmiCustom([string]$computername,[string]$namespace,[string]$class,[int]$timeout=15)<br />
{<br />
$ConnectionOptions = new-object System.Management.ConnectionOptions<br />
$EnumerationOptions = new-object System.Management.EnumerationOptions</p>
<p>$timeoutseconds = new-timespan -seconds $timeout<br />
$EnumerationOptions.set_timeout($timeoutseconds)</p>
<p>$assembledpath = &#034;\\&#034; + $computername + &#034;\&#034; + $namespace<br />
#write-host $assembledpath -foregroundcolor yellow</p>
<p>$Scope = new-object System.Management.ManagementScope $assembledpath, $ConnectionOptions<br />
$Scope.Connect()</p>
<p>$querystring = &#034;SELECT * FROM &#034; + $class + &#034; where DriveType=3 AND DeviceID=&#039;C:&#039;&#034;<br />
#write-host $querystring</p>
<p>$query = new-object System.Management.ObjectQuery $querystring<br />
$searcher = new-object System.Management.ManagementObjectSearcher<br />
$searcher.set_options($EnumerationOptions)<br />
$searcher.Query = $querystring<br />
$searcher.Scope = $Scope</p>
<p>trap { $_ } $result = $searcher.get()</p>
<p>return $result<br />
}</p>
<p>$csv = &#034;machines.csv&#034;</p>
<p>$import = Import-CSV $csv</p>
<p>$import | foreach {<br />
get-wmicustom -class win32_logicaldisk -namespace &#034;root\cimv2&#034; -computername {$_.hostname} | Select SystemName,DeviceID,VolumeName,@{Name=&#034;size(GB)&#034;;Expression={&#034;{0:N1}&#034; -f($_.size/1gb)}},@{Name=&#034;freespace(GB)&#034;;Expression={&#034;{0:N1}&#034; -f($_.freespace/1gb)}}<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Daniele Muscetta</title>
		<link>http://www.muscetta.com/2009/05/27/get-wmicustom/comment-page-1/#comment-29148</link>
		<dc:creator>Daniele Muscetta</dc:creator>
		<pubDate>Fri, 25 Sep 2009 09:57:06 +0000</pubDate>
		<guid isPermaLink="false">http://www.muscetta.com/?p=443#comment-29148</guid>
		<description>I have not seen this... but that is what the trap is for.

try changing
trap { $_ } $result = $searcher.get() 

to 
trap { $_; continue } $result = $searcher.get()</description>
		<content:encoded><![CDATA[<p>I have not seen this&#8230; but that is what the trap is for.</p>
<p>try changing<br />
trap { $_ } $result = $searcher.get() </p>
<p>to<br />
trap { $_; continue } $result = $searcher.get()</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Andrew</title>
		<link>http://www.muscetta.com/2009/05/27/get-wmicustom/comment-page-1/#comment-29147</link>
		<dc:creator>Andrew</dc:creator>
		<pubDate>Wed, 23 Sep 2009 14:17:59 +0000</pubDate>
		<guid isPermaLink="false">http://www.muscetta.com/?p=443#comment-29147</guid>
		<description>Hello! 

I&#039;m writing script for collecting network adapters data using WMI.
I tried to use your great code (ooh, that 10 000 000 days timeout was a someone&#039;s crazy idea... ), but have faced some problems.
The code works well if queried computer is either available or totally offline. If it is online but do not returns WMI object properly, I have PowerShell totally crashed with the message &quot;An error has occurred that was not properly handled. Addidtional information is shown below. The Windows PowerShell process will exit&quot;. After that PowerShell console closing... Do you have any idea how to fix such behaviour?

I am using such function call: get-wmicustom -class win32_networkadapterconfiguration -namespace &quot;root\cimv2&quot; -computername sunset -timeout 10
Crash occurs when executing $result = $searcher.get() reaching timeout.

Thank you very much.</description>
		<content:encoded><![CDATA[<p>Hello! </p>
<p>I&#039;m writing script for collecting network adapters data using WMI.<br />
I tried to use your great code (ooh, that 10 000 000 days timeout was a someone&#039;s crazy idea&#8230; ), but have faced some problems.<br />
The code works well if queried computer is either available or totally offline. If it is online but do not returns WMI object properly, I have PowerShell totally crashed with the message &#034;An error has occurred that was not properly handled. Addidtional information is shown below. The Windows PowerShell process will exit&#034;. After that PowerShell console closing&#8230; Do you have any idea how to fix such behaviour?</p>
<p>I am using such function call: get-wmicustom -class win32_networkadapterconfiguration -namespace &#034;root\cimv2&#034; -computername sunset -timeout 10<br />
Crash occurs when executing $result = $searcher.get() reaching timeout.</p>
<p>Thank you very much.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

