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?
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'}
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:
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'}
}
ASKER
cim-instance keeps saying :
WARNING: [WSManNetworkFailureDetect ed] 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
WARNING: [WSManNetworkFailureDetect
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
ASKER
@jason: ID: 42416756
there is no timeout in this script, this is the script which is getting stuck in one of the servers..
there is no timeout in this script, this is the script which is getting stuck in one of the servers..
ASKER
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'}
Get-CimInstance -class Win32_LogicalDisk -Filter "Drivetype=3" -Cimsession $CimSession -OperationTimeoutSec 1 | Where-Object { ($_.freespace/$_.size) -le '0.1'}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank You Jason! Appreciate your help!
Glad I could help. Take care :)
https://blogs.technet.microsoft.com/heyscriptingguy/2016/02/08/should-i-use-cim-or-wmi-with-windows-powershell/