Monday, September 17, 2012

PowerShell - Get List of files in a Folder path recursively and export to CSV file the output



In this blog post i will discuss document some PowerShell scripts that will help you
  1. Get List of files in a Folder path recursively and export to a CSV file the output with the files meta data information like ( Directory, Name, Length, CreationTime, LastWriteTime, LastAccessTime, FullName, Extension )
  2. Get Distinct COUNT of File extensions inside a folder path recursively.

Get List of files recursively and export to a CSV file with the files meta data information

Open PowerShell
%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe

Get-Childitem "C:\Bharath\Files" -Recurse | where { -not $_.PSIsContainer } | Select Directory, Name, Length, CreationTime, LastWriteTime, LastAccessTime, FullName, Extension | Export-Csv "C:\Users\E317351\Desktop\FileswithSize.txt"


Get Distinct COUNT of File extensions inside a folder path recursively.

Open PowerShell
%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe

Get-Childitem "C:\Bharath\Desktop\Some Folders" -Recurse | where { -not $_.PSIsContainer } | group Extension -NoElement | sort count -desc

Exclude some folder (use -exclude) parameter as below

Get-Childitem "C:\Bharath\Desktop\Some Folders" -exclude TestFolderName -Recurse | where { -not $_.PSIsContainer } | group Extension -NoElement | sort count -desc