This function will allow you to take the size of anything in bytes and convert it to the highest possibly value type such as KB,MB,GB, etc... The function uses P/Invoke to work with the Win32 APIs that will handle the bytes conversion, similiar to what you will see in Windows Explorer.
Load function into memory
 
 
 
PowerShell
Edit|Remove
. .\convert-size.ps1
 
 
Take output from Get-ChildItem and custom format it to show highest value
 
PowerShell
Edit|Remove
Get-ChildItem| ? {!$_.PSIsContainer} |Select-First 5 |Select Name,  
@{L='Size';E={$_| Convert-Size}}
 
        Name                          Size                                                         
        ----                          ----                                                         
        Data1.cap                     14.4 MB                                                      
        Data2.cap                     12.5 MB                                                      
        Image.iso                     5.72 GB                                                      
        Index.txt                     23.9 KB                                                      
        SomeSite.lnk                  1.52 KB    
        SomeFile.ini                  152 bytes