aboutsummaryrefslogtreecommitdiff
path: root/scripts/azure-pipelines/windows/disk-space.ps1
blob: 8680d770158c35e645192544ca0943541766d21f (plain)
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
# Copyright (c) Microsoft Corporation.
# SPDX-License-Identifier: MIT
#

<#
.SYNOPSIS
Prints total and free disk space for each disk on the system
#>

Function Format-Size {
    [CmdletBinding()]
    Param([long]$Size)

    if ($Size -lt 1024) {
        $Size = [int]$Size
        return "$Size B"
    }

    $Size = $Size / 1024
    if ($Size -lt 1024) {
        $Size = [int]$Size
        return "$Size KiB"
    }

    $Size = $Size / 1024
    if ($Size -lt 1024) {
        $Size = [int]$Size
        return "$Size MiB"
    }

    $Size = [int]($Size / 1024)
    return "$Size GiB"
}

Get-CimInstance -ClassName Win32_LogicalDisk | Format-Table -Property @{Label="Disk"; Expression={ $_.DeviceID }},@{Label="Label"; Expression={ $_.VolumeName }},@{Label="Size"; Expression={ Format-Size($_.Size) }},@{Label="Free Space"; Expression={ Format-Size($_.FreeSpace) }}