0

I've had a script running for the better half of a year now that checks for disk space, should it be low it sends out an email been working just fine.

Today I received an alert saying that that Disk space was at 0gb.. I logged into the server and had about 30gbs available.

Part of code that checks the space.

[decimal]$thresholdspace = 5
$tableFragment= Get-WMIObject  -ComputerName $computer Win32_LogicalDisk `
| select __SERVER, DriveType, VolumeName, Name, @{n='Size (Gb)' ;e={"{0:n2}" -f ($_.size/1gb)}},@{n='FreeSpace (Gb)';e={"{0:n2}" -f ($_.freespace/1gb)}}, @{n='PercentFree';e={"{0:n2}" -f ($_.freespace/$_.size*100)}} `
| Where-Object {$_.DriveType -eq 3 -and [decimal]$_.PercentFree -lt [decimal]$thresholdspace} 

So I opened up an ISE session and did the following.

$computer = 'Server_01'

Get-WMIObject  -ComputerName $computer Win32_LogicalDisk | select __SERVER, DriveType, VolumeName, Name,FreeSpace

and it responded with:

__SERVER   : Server_01
DriveType  : 2
VolumeName : 
Name       : A:
FreeSpace  : 

__SERVER   : Server_01
DriveType  : 3
VolumeName : 
Name       : C:
FreeSpace  : 31372767232

__SERVER   : Server_01
DriveType  : 5
VolumeName : 
Name       : E:
FreeSpace  : 

So I then ran the part of my code that is getting space and it returned with the following:

__SERVER       : Server_01
DriveType      : 3
VolumeName     : 
Name           : C:
Size (Gb)      : 0.00
FreeSpace (Gb) : 0.00
PercentFree    :

So I ran the simple WMI query and it responded with no data..

__SERVER   : Server_01
DriveType  : 2
VolumeName : 
Name       : A:
FreeSpace  : 

__SERVER   : Server_01
DriveType  : 3
VolumeName : 
Name       : C:
FreeSpace  : 

__SERVER   : Server_01
DriveType  : 5
VolumeName : 
Name       : E:
FreeSpace  : 

Any idea as to why I'm getting invalid or what appears to be incomplete data? I've never seen anything like this, and have not ran into this issue at all before. Nothing has changed on either server it is running from.

JonnyBoy
  • 417
  • 1
  • 6
  • 16
  • Can be simplified to just that "Get-WMIObject -ComputerName $computer Win32_LogicalDisk" is returning blank VolumeName and FreeSpace? Does this happen constantly, or intermittently? All servers, some servers, localhost? If intermittent, maybe unroll your complex code into steps, making it easier to debug, read, and maintain, and then loop/sleep until you have data. – Kory Gill Nov 03 '16 at 00:13
  • Slight tangent, but ... reboot the server. Come on, you know there's a reasonable chance it will magically work after. Also, the output changed - what else changed recently? Installed/uninstalled/patched/upgraded/settings changed? – TessellatingHeckler Nov 03 '16 at 01:12
  • Kory - You are correct, it was returning a blank Value and is happening Intermittently only on this one server. I don't see the code being the issue here as just Get-WmiObject -ComputerName $computer Win32_logicalDisk also returned blank. As to TessellatingHecklers point, there is magically that chance, but literally nothing on the servers have changed.. I can reboot the server making the calls but i cannot reboot the server i'm getting the information from at this moment. – JonnyBoy Nov 03 '16 at 22:21
  • Sorry, have to have 50 reputation to comment. Have to add comment as an answer. What happens if you run: get-ciminstance -computername $computer -classname Win32_Logicaldisk – Tim Haintz Nov 03 '16 at 01:40

0 Answers0