-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFunction_Get_DiskUsage.ps1
More file actions
31 lines (25 loc) · 1.03 KB
/
Function_Get_DiskUsage.ps1
File metadata and controls
31 lines (25 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# Parameters: ComputerName - Use computer name if computer name DNS resolvable, else use IP address.
function Get-DiskUsage{
Param(
[Parameter()]
$ComputerName
)
$MemoryArray = New-Object System.Collections.ArrayList
foreach($Computer in $ComputerName){
if( -not (Test-Connection -ComputerName $Computer -Quiet -Count 1)){
Write-Host "$($Computer) is not available" -ForegroundColor Red
continue
}
# Get disk information
$CDrive = Get-WmiObject -Class win32_logicaldisk -ComputerName $Computer | where DeviceID -EQ 'C:'
$FreeSpace = [math]::Round(($CDrive.FreeSpace/1073741824), 2)
$DiskUsage = 100 - [math]::Round(($CDrive.Freespace / $CDrive.Size)*100,2)
$TempObject = [pscustomobject]@{
'ComputerName' = $Computer
'Freespace GB' = $FreeSpace
'Disk Usage %' = $DiskUsage
}
$MemoryArray.add($TempObject) | out-null
}
return $MemoryArray
}