Friday, November 25, 2011

“Find how many types of files you have in you laptop” using Powershell.



Today i was searching for one PDF file on my laptop and then I just thinks “How Many PDF files do i have?”, i have no idea, one way to find is go to windows search and find all .PDF files? but “how can i find this with powershell”

we can

let try it ..

Cmdlet Used: Get-ChildItem,Group-Object, Sort-Object

Command: $files =  Get-ChildItem -Path C:\Users\aman.dhally\Documents –Recurse

In $files variable i am saving the result of Get-ChildItem -Path C:\Users\aman.dhally\Documents –Recurse  command , Get-ChildItem in equal as DIR command and we are using –Path switch parameter to give the path of the folder in which we want to search for files, –Recurse means including sub folders.


lets run $files variable and see what it has stored

It showing the files and folders located in my “Document” folder


let filer the results

$files | Group-Object -Property Extension | Sort-Object Count –Descending

now pipe the $files variable to Group-Object cmdlet and the grouping Property is Extensions because we want to group files by there extensions, now piped the command to Sort-Object and we are sorting the results by Count,

OoPs 751 .torrent files,, going to delete them . )



aman dhally

No comments:

Post a Comment