I am currently working on a script that needs to do the following :
- Find all duplicate files on a specific folder based on their hash
- Display their path and size
- Export the results into a csv
But I don’t want the script to go into subfolders that are symbolic links
And that’s my issue. No matter what I do, the script refuses to ignore those “symbolic link” type subfolders
Here’s what the script looks like right now, which is working aside from the “symbolic link” exclusion issue :
Get-ChildItem -Path $srcDir -File -Recurse |
Group-Object -Property Length |
Where-Object Count -GT 1 |
ForEach-Object Group |
Get-FileHash |
Group-Object Hash |
Where-Object Count -GT 1 |
ForEach-Object Group |
Select-Object Path, Hash, @{ N = 'Length'; E = { [System.IO.FileInfo]::new($_.Path).Length}} |
Export-Csv -Path C:TempResult.csv -NoTypeInformation
The folder “C:UserstestDocumentsfolder”, contains 2 sub-folders (named “Subfolder_A” and “Subfolder_B”) that are symbolic links
And the script always icludes them into the search despite me not wanting to
Here’s what I tried so far
I changed the Get-ChildItem line by this :
Get-ChildItem -Path $srcDir -File -Recurse | Where-Object -property Attributes -NotLike -value "*ReparsePoint*" |
This :
Get-ChildItem -Path $srcDir -File -Recurse | Where-Object Attributes -NotLike "*ReparsePoint*" |
And this :
Get-ChildItem -Path $srcDir -File -Recurse | Where-Object{$_.Name -notmatch ("Subfolder_A" -join "|")} |
But it stills goes into “Subfolder_A” and “Subfolder_B”
I don’t know why the script refuses to bypass symbolic links.
Thanks in advance for your help
KaKouss Night is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
0
The recurse parameter does some surprising things. You can pipe get-childitem to itself:
Get-ChildItem -Attributes !reparsepoint | get-childitem -recurse #...
2