function Get-LocalDiskInfo {

    [CmdletBinding()] param (
        [parameter(Mandatory=$true)] [string]$ComputerName,
        [parameter(Mandatory=$false)] [Management.Automation.PSCredential] $Credential
    )
    PROCESS {

        $results = @()

        try {
            
            if($Credential) {
                $localDisks = Get-WmiObject -Class Win32_LogicalDisk -ComputerName $ComputerName -Credential $Credential | ?{$_.DriveType -eq 3}
            }
            else {
                $localDisks = Get-WmiObject -Class Win32_LogicalDisk -ComputerName $ComputerName | ?{$_.DriveType -eq 3}
            }
            
            foreach ($localDisk in $localDisks) {
                $custDiskObj = New-Object PSObject -Property @{
                    SystemName = $ComputerName
                    DriveLetter = $localDisk.DeviceID.TrimEnd(':')
                    VolumeName = $localDisk.VolumeName
                    CapacityGB = [System.Math]::Round($localDisk.Size/1024/1024/1024, 2)
                    FreeSpaceGB = [System.Math]::Round($localDisk.FreeSpace/1024/1024/1024, 2)
                    PercentFree = $null
                }
                if($localDisk.FreeSpace -ne 0) {
                    $custDiskObj.PercentFree = [System.Math]::Round(($localDisk.FreeSpace*100/$localDisk.Size), 0)
                }
                else {
                    $custDiskObj.PercentFree = 0
                }
                
                $results += $custDiskObj
            }
        }
        catch {
            Write-Host "`n$_`n" -ForegroundColor Magenta
            return
        }
        return $results | select SystemName,DriveLetter,VolumeName,CapacityGB,FreeSpaceGB,PercentFree | sort PercentFree
    }
}

function Get-LocalDiskReport {
    [CmdletBinding()] param (
        [parameter(Mandatory=$true)] [array]$ComputerNameList,
        [parameter(Mandatory=$false)] [Management.Automation.PSCredential] $Credential
    )
    PROCESS {
    
        $results = @()
    
        $ComputerNameList | %{
            if($Credential) {
                $results += Get-LocalDiskInfo -ComputerName $_ -Credential $Credential
            }
            else {
                $results += Get-LocalDiskInfo -ComputerName $_
            }
        }
        
        return $results | sort PercentFree
    }
}