function DiskFree($dir = "") { $wmiq = 'SELECT * FROM Win32_LogicalDisk WHERE Size != Null AND DriveType >= 2' $disks = Get-WmiObject -Query $wmiq [System.Collections.ArrayList]$newary = @() foreach ($disk in $disks) { # Write-Host "Processing " $disk.deviceId $used = ( $disk.Size - $disk.FreeSpace ) $percent = [math]::Round($used / $disk.size * 100,1) $freePercent = [math]::Round($disk.FreeSpace / $disk.size * 100,1) if ( ($dir -ne "" -and $dir -eq $disk.DeviceID) -or ($dir -eq "") ) { $dfObject = New-Object -TypeName psobject $dfObject | Add-Member -MemberType NoteProperty -Name Device -Value $disk.deviceId $dfObject | Add-Member -MemberType NoteProperty -Name Used -Value $used $dfObject | Add-Member -MemberType NoteProperty -Name UsedPercent -Value $percent $dfObject | Add-Member -MemberType NoteProperty -Name Free -Value $disk.FreeSpace $dfObject | Add-Member -MemberTYpe NoteProperty -Name FreePercent -Value $freePercent $dfObject | Add-Member -MemberTYpe NoteProperty -Name Total -Value $disk.size $res = $newary.Add($dfObject) } # Write-Host "Processed" $disk.DeviceId } $newary } function df($dir="") { DiskFree($dir) | Format-Table -Property Device,Used,UsedPercent,Free,FreePercent,Total -AutoSize }
Where Will All of Big Tech’s Nuclear Waste Go?
9 minutes ago
No comments:
Post a Comment