redhottsili

MyTypes.ps1xml

Feb 27th, 2021 (edited)
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
XML 1.01 KB | None | 0 0
  1. <?xml version="1.0" encoding="utf-8" ?>
  2. <Types>
  3.     <Type>
  4.         <Name>System.IO.FileInfo</Name>
  5.         <Members>
  6.             <ScriptProperty>
  7.                 <!-- Filesize converts the length to a human readable
  8.                    format (kb, mb, gb, tb) -->
  9.                 <Name>FileSize</Name>
  10.                 <GetScriptBlock>
  11.                     switch($this.length) {
  12.                         { $_ -gt 1tb }
  13.                             { "{0:n2} TB" -f ($_ / 1tb) ; break }
  14.                         { $_ -gt 1gb }
  15.                             { "{0:n2} GB" -f ($_ / 1gb) ; break }
  16.                         { $_ -gt 1mb }
  17.                             { "{0:n2} MB " -f ($_ / 1mb) ; break }
  18.                         { $_ -gt 1kb }
  19.                             { "{0:n2} KB " -f ($_ / 1Kb) ; break }
  20.                         default
  21.                             { "{0}  B " -f $_}
  22.                     }
  23.                 </GetScriptBlock>
  24.             </ScriptProperty>
  25.         </Members>
  26.     </Type>
  27. </Types>
Add Comment
Please, Sign In to add comment