Sunday, August 19, 2012 11:06 PM
i'm wondering if there is any solution for a problem i'm facing.
I'm trying to use powershell to build a statistic of the file types present on a given drive
i'm using file extension to classify files with this command
"Get-ChildItem X: -recurse -Force | Select-Object Extension | Group-Object Extension | Sort-Object Count -Descending > C:\Stats\DriveX.txt"
the command above produce a text files in which every line reports the number of files that have a certain extension.
The problem is that when the command encounters junction points on the target drive (X: in the example) it "deviates" on the corresponding
directory on MY C: drive and so happens that (to make an example) .lnk files reported as
"X:\Users\All Users\Microsoft\Windows\Start Menu\Programs\" are effectively coming from "C:\Users\All Users\Microsoft\Windows\Start Menu\Programs\".
Does anyone knows of a way to tell Get-ChildItem no to follow junction points (something like the "/XJ" parameter of robocopy) ??
Monday, August 20, 2012 12:29 AM
Yes - that is an issue because 'reparse points ' behave transparently.
Reparse points or hard links are designed to make files and folders look like they are in the folder or on the drive being enumerated. Consequently, simple file enumeration schemes like PowerShell uses cannot tell that these objects are not on the path being enumerated.
Friday, August 31, 2012 3:12 PM
Just in case it could be of any use to someone i resolved the problem this way:
1) I created a full directory listing of the mounted drive letter (X:) with ROBOCOPY that has a parameter to tell it not to follow junction points like this:
robocopy X: C: *.* /L /FP /R:0 /NS /NC /NJH /NJS /XX /S /XJ > C:\RoboFileListing.txt
2) I built the statistic with LOGPARSER like this:
LogParser -i:TEXTLINE -o:TSV "SELECT CASE EXTRACT_EXTENSION(LTRIM(RTRIM(Text))) WHEN '' THEN 'NO_EXTENSION' ELSE EXTRACT_EXTENSION(LTRIM(RTRIM(Text))) END AS Extension, COUNT(Extension) AS HowManyFiles FROM C:\RoboFileListing.txt GROUP BY Extension ORDER BY HowManyFiles DESC" > C:\STAT.TXT
this creates the file "C:\STAT.TXT" with 2 columns like this: