Good morning,
So I have been teaching myself PowerShell, and I have come across a nagging question to a problem I am having at work. so to minimize time on system checks I am trying to write something that can be run and return a value of say a system with less then X% free space on a given drive.
I have put the list of hostnames into a file and have done a get-content etc into a $servers variable the below code works and displays lists of the servers and the drive size on freespace etc. so works OK. but i want it better
foreach ($server in $servers) {
Get-WmiObject Win32_LogicalDisk -ComputerName $server | format-table deviceid, @{n="Size";e={[math]::Round($_.Size/1GB,2)}},@{n="FreeSpace";e={[math]::Round($_.FreeSpace/1GB,2)}}
}
What I want to do is take the output of the foreach
into variables that I can then run some math of to get % then get an output to something say below 20%
but for the life of me I cannot figure out how to get the output of this to variable i can call
deviceid Size FreeSpace
-------- ---- ---------
C: 69.51 42.5
D: 400 146.73
E: 10 6.67
X: 0 0
This being the output so no server names etc. If I knew how to articulate what it actually is I want I would be able to find it I know. but I can't.
Any help would be amazing