-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathcapacity.ps1
More file actions
35 lines (27 loc) · 936 Bytes
/
capacity.ps1
File metadata and controls
35 lines (27 loc) · 936 Bytes
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
32
33
34
35
# Drive letter is passed in
$driveLetter = $args[0]
if ($driveLetter -eq $null) {
Write-Output "WARNING: drive not provided - defaulting to c: for test"
$driveLetter = "C:"
}
# Add ":" to the drive letter if it's missing
if (-not $driveLetter.EndsWith(':')) {
$driveLetter += ':'
}
# Get disk information using Get-CimInstance
$disk = Get-CimInstance -ClassName Win32_LogicalDisk -Filter "DeviceID='$driveLetter'"
# Calculate disk space values in GB
$totalSpaceGb = [Math]::Round($disk.Size / 1GB, 2)
$freeSpaceGb = [Math]::Round($disk.FreeSpace / 1GB, 2)
$usedSpaceGb = [Math]::Round(($disk.Size - $disk.FreeSpace) / 1GB, 2)
# Create a hashtable with the results
$diskUsage = @{
Drive = $driveLetter
TotalSpaceGb = $totalSpaceGb
FreeSpaceGb = $freeSpaceGb
UsedSpaceGb = $usedSpaceGb
}
# Convert the hashtable to JSON
$jsonOutput = $diskUsage | ConvertTo-Json
# Output the JSON
Write-Output $jsonOutput