我正在嘗試獲得像磁盤管理中存在的免費百分比
$Diskmgmt = Get-Volume | select DriveLetter,FileSystemLabel,FileSystem,DriveType,HealthStatus,OperationalStatus,SizeRemaining,Size
foreach($dsk in $Diskmgmt)
{
$dl = $dsk.DriveLetter
$fsl = $dsk.FileSystemLabel
$fs = $dsk.FileSystem
$dt = $dsk.DriveType
$hs = $dsk.HealthStatus
$os = $dsk.OperationalStatus
$sizer = [math]::round($dsk.SizeRemaining /1Gb, 2)
$siz = [math]::round($dsk.Size /1Gb, 2)
$PercentFree = [Math]::Round(($sizer / $siz) * 100, 2)
但計算如下
Capacity Free Space %Free
154.82 GB 200 GB 77 %
0 GB 0 GB 77 %
1.96 GB 6 GB 33 %
0.15 GB 0.49 GB 31 %
52.32 GB 99.51 GB 53 %
11.19 GB 11.23 GB 100 %
9.95 GB 10 GB 99 %
請讓我知道我是否做對了。
uj5u.com熱心網友回復:
使用 get-psdrive 和“p”格式說明符:
get-psdrive c | % { $_.free/($_.used $_.free) } | % tostring p
9.24%
uj5u.com熱心網友回復:
我猜你正在尋找這樣的東西:
$props = @(
'DriveLetter'
'FileSystemLabel'
'FileSystem'
'DriveType'
'HealthStatus'
'OperationalStatus'
@{n='SizeRemaining';e={"{0:N3} Gb" -f ($_.SizeRemaining/ 1Gb)}}
@{n='Size';e={"{0:N3} Gb" -f ($_.Size / 1Gb)}}
@{n='% Free';e={"{0:P}" -f ($_.SizeRemaining / $_.Size)}}
)
Get-Volume -DriveLetter C, D | Select-Object $props | Format-Table
例如,這就是它在我的筆記本電腦上的 DrivesC和D:
DriveLetter FileSystemLabel FileSystem DriveType HealthStatus OperationalStatus SizeRemaining Size % Free
----------- --------------- ---------- --------- ------------ ----------------- ------------- ---- ------
D NTFS Fixed Healthy OK 748.731 Gb 931.512 Gb 80.38%
C NTFS Fixed Healthy OK 170.959 Gb 236.764 Gb 72.21%
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/338521.html
標籤:电源外壳
