get-wmiobject timeout

Hi Experts,

I am trying to create a report of servers with less than 10 percent disk space. However when I run it across our server list it hangs on some systems. I heard that get-wmiobject doesnt have an option to timeout.

Could you please help me create a timeout for this get-wmiobject?

$DiskReport = ForEach ($Servernames in ($File)) 

{write-host $Servernames
$pspassword = ConvertTo-SecureString “somepassword” -AsPlainText -Force
$Cred = New-Object System.Management.Automation.PSCredential (“someuser”, $pspassword)
Get-WmiObject win32_logicaldisk -Credential $Cred `
-ComputerName $Servernames -Filter "Drivetype=3" `
-ErrorAction SilentlyContinue | 

#return only disks with
#free space less  
#than or equal to 0.1 (10%)

Where-Object {   ($_.freespace/$_.size) -le '0.1'}

Open in new window

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jason CrawfordTransport NinjaCommented:
Jason CrawfordTransport NinjaCommented:
Here is a script from the PS Gallery:

Otherwise here is my version of your script:

$pspassword = ConvertTo-SecureString 'somepassword' -AsPlainText -Force
$Cred = New-Object System.Management.Automation.PSCredential ('someuser', "$pspassword")

foreach ($servername in $file) {
    write-host $Servername
    Get-WmiObject win32_logicaldisk -Credential $Cred -ComputerName $Servername -Filter "Drivetype='3'" | Where-Object {($_.freespace/$_.size) -le '0.1'}

Open in new window

DevSupportAuthor Commented:
cim-instance keeps saying :

WARNING: [WSManNetworkFailureDetected] The network connection to SERVERNAME
has been interrupted. Attempting to reconnect for up to 4 minutes...

Each system waiting for four minutes is making the script time exponentially high.

Another issue is:

New-CimSession : WinRM cannot complete the operation. Verify that the
specified computer name is valid, that the computer is accessible over the
network, and that a firewall exception for the WinRM service is enabled and
allows access from this computer. By default, the WinRM firewall exception for
public profiles limits access to remote computers within the same local subnet.

and wmiobject works a little better than cim-instance
Creating Active Directory Users from a Text File

If your organization has a need to mass-create AD user accounts, watch this video to see how its done without the need for scripting or other unnecessary complexities.

DevSupportAuthor Commented:
@jason: ID: 42416756
there is no timeout in this script, this is the script which is getting stuck in one of the servers..
DevSupportAuthor Commented:
when I do this I get lot of WinRM errors:

Get-CimInstance -class Win32_LogicalDisk -Filter "Drivetype=3" -Cimsession $CimSession -OperationTimeoutSec 1 | Where-Object {   ($_.freespace/$_.size) -le '0.1'}
Jason CrawfordTransport NinjaCommented:
Is the remote server running any kind of anti-virus software?

Try this:

Get-CimInstance -ClassName Win32_LogicalDisk -Filter "Drivetype='3'" | Where-Object {($_.freespace/$_.size) -le '0.1'} 

Open in new window

When you're filtering WMI or CIM I always enclose the value I'm filtering for in single quotes as you can see above.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
DevSupportAuthor Commented:
Thank You Jason! Appreciate your help!
Jason CrawfordTransport NinjaCommented:
Glad I could help.  Take care :)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.