Diskusage in Powershell

Here is a small Snippet who shows you the Size of all Diskdrives in Powershell. It works also in remotly.

function global:DiskUsage
    param([string]$servername = "localhost")

    $pingresult=(Get-WmiObject -Class Win32_PingStatus -Filter "Address='$servername'" -ComputerName . | select Statuscode)
    if($pingresult.Statuscode -ne $null -and $pingresult.Statuscode -eq 0)
        get-wmiobject Win32_LogicalDisk -computername $servername -filter ("DriveType <4 and DriveType > 2") -ErrorAction silentlycontinue | Select-Object -Property systemname, VolumeName, DeviceID, DriveType, ProviderName, FreeSpace, Size, @{Name="Freespace GB";Expression={((($_.FreeSpace/1024)/1024)/1024).ToString("F2")}}, @{Name="Size GB";Expression={((($_.Size/1024)/1024)/1024).ToString("F2")}}




Hinterlassen Sie einen Kommentar