print sizes of all folder and files in each drive using powershell -


i running below powershell command getting error:trying calculate sizes of folder , files in each drive if size lessthan 1kb print size in kb otherwise in mb or gb

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 

error

    missing '=' operator after key in hash literal.     @ 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 

as error message hints at, can't place value expression directly inside hashtable literal.

move condition inside expression scriptblock:

@{     label="totalsize (mb)"     expression={         if($_.length -lt 1kb){             [math]::truncate($_.length / 1kb)         }         else{             [math]::truncate($_.length / 1gb)         }     }     width=14 } 

although think should remove (mb) part of label in case, since you're not showing size in mb.


Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -