Link to home
Start Free TrialLog in
Avatar of DevSupport
DevSupport

asked on

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

Avatar of Jason Crawford
Jason Crawford
Flag of United States of America image

Here is a script from the PS Gallery:

https://gallery.technet.microsoft.com/scriptcenter/Disk-Space-Report-Reports-98e64d65

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

Avatar of DevSupport
DevSupport

ASKER

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
@jason: ID: 42416756
there is no timeout in this script, this is the script which is getting stuck in one of the servers..
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'}
ASKER CERTIFIED SOLUTION
Avatar of Jason Crawford
Jason Crawford
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank You Jason! Appreciate your help!
Glad I could help.  Take care :)