PS: Directory Listing

Command to list all Files greater than a specified file size:

PS D:> Dir $env:windir | Where-Object { $_.Length -gt 10MB }

    Directory: C:Windows

Mode                LastWriteTime     Length Name
—-                ————-     —— —-
-a—         3/18/2011  11:00 PM  262189444 MEMORY.DMP

PS D:>

 

Format the File listing by the File sizes in KB, MB, GB’s:

 

PS D:> Dir $env:windir | Where-Object { $_.Length -gt 1MB } | Format-Table Name, { [int]($_.Length/1MB) } -Auto

Name                   [int]($_.Length/1MB)
—-                  ———————-
explorer.exe                               2
MEMORY.DMP                               250
ntbtlog.txt                                1
setupact.log                               3
WindowsUpdate (1).log                      2
WindowsUpdate.log                          1
wweb32.dll                                 1

PS D:>

 

Display matching Files with sizes in KB, MB, GB’s

 

PS D:> Dir $env:windir | Where-Object { $_.Length -gt 1MB } | ForEach-Object { "{0,-25} {1,10} MB" -f $_.name,  [int]($_.Length/1MB) }
explorer.exe                       2 MB
MEMORY.DMP                       250 MB
ntbtlog.txt                        1 MB
setupact.log                       3 MB
WindowsUpdate (1).log              2 MB
WindowsUpdate.log                  1 MB
wweb32.dll                         1 MB
PS D:>

Leave a Reply

Your email address will not be published. Required fields are marked *