我運行在PowerShell命令下面我得到錯誤:如果大小小於1KB,試圖計算每個驅動器中文件夾和文件的大小,然後以KB爲單位打印大小MB或GB
使用PowerShell每個驅動器中的所有文件夾和文件的打印大小
ls -Force | Add-Member -Force -Passthru -Type ScriptProperty -Name Length -Value {ls $this -Recurse -Force | Measure -Sum Length | Select -Expand Sum } | Sort-Object Length -Descending | Format-Table @{label="TotalSize (MB)";If ($_.Length -lt 1KB) {expression={[Math]::Truncate($_.Length/1KB)};width=14} else {expression={[Math]::Truncate($_.Length/1GB)};width=14}}, @{label="Mode";expression={$_.Mode};width=8}, Name
錯誤
Missing '=' operator after key in hash literal.
At line:1 char:230
+ ls -Force | Add-Member -Force -Passthru -Type ScriptProperty -Name
Length -Value {ls $this -Recurse -Force | Measure
Sum Length | Select -Expand Sum } | Sort-Object Length -Descending |
Format-Table @{label="TotalSize (MB)";If (<<<< $
_.Length -lt 1KB) {expression={[Math]::Truncate($_.Length/
1KB)};width=14} else {expression={[Math]::Truncate($_.Lengt
h/1GB)};width=14}}, @{label="Mode";expression={$_.Mode};width=8},
Name
+ CategoryInfo : ParserError: (:) [],
ParentContainsErrorRecordException
+ FullyQualifiedErrorId : MissingEqualsInHashLiteral
在'expression = {}'塊內移動'if/else' –