- 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:\Temp\Result.csv -NoTypeInformationAnd 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*" |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

Why use Git for your profile
Storing your PowerShell profile in Git has several benefits:
- Version control: You can track changes to your profile script over time, which is invaluable
for understanding the history of your modifications and for recovery in case of an error. - Consistency: It allows you to synchronize your profile across multiple machines, ensuring a
consistent environment everywhere you use PowerShell. - Collaboration: If you’re working with a team, sharing a PowerShell profile can help
standardize the working environment.
The role of symbolic links
Symbolic links (symlinks) are a feature of the file system that creates a type of shortcut to a file
or directory. Using a symlink, you can store your profile in a Git repository and link to it from
the default PowerShell profile path. PowerShell can access the profile as if it were in its original
location while you maintain the actual file in a version-controlled repository.
How to store your profile in a Git repo using symbolic links
Create a Git repository: If you haven’t already, set up a Git repository where you’ll store
your PowerShell profile. You can create a new repository on services like GitHub, GitLab, or
Bitbucket and then clone it locally to your computer.Move your existing profile: Move your current PowerShell profile to the local clone of your
new Git repository. If you don’t have a profile yet, create one in the repository folder.-------- ---- ----- ------------- ---- -----rw-r--r-- mikefrobbins staff 11/8/2023 17:59 97 Microsoft.PowerShell_profile.ps1 ->Commit your profile to Git: Using the standard Git commands, add your profile to the
repository and commit it.'Added PowerShell profile'1 file changed, 107 insertions(+) create mode 100644 PowerShell/Microsoft.PowerShell_profile.ps1Enumerating objects: 5, done.Counting objects: 100% (5/5), done.Delta compression using up to 12 threadsCompressing objects: 100% (4/4), done.Total 4 (delta 1), reused 0 (delta 0), pack-reused 0remote: Resolving deltas: 100% (1/1), completed with 1 local objects. fec6836..aaa6432 main -> mainClone and link your other systems: On your other systems, clone the repository and create a
symbolic link. Now, you’ve synchronized your PowerShell profile across your machines.
Best practices
- Backup before changes: Always back up your profile before making changes or updates to avoid
any loss of important configurations. - Commit regularly: Make it a habit to commit changes to your profile as you make them,
including meaningful commit messages to track your changes. - Test your profile: Ensure your profile scripts work as intended on new machines to avoid
system-specific configurations that may not translate across different environments.
Acknowledgments
Thanks to Sean Wheeler for the tip about using symbolic links to store PowerShell
profiles in a Git repo.
My application is writing logs to a directory, which is hardcoded “Logs” and is present under the runtime directory of my application.
Today, a customer asked me if it was possible to have those logs on another place (on another computer).
As a first test, I tried to create a symlink:
- I stopped the application.
- I removed the “Logs” directory.
- Using a WSL on my computer, I created a symlink, something like
ln -s /mnt/c/Temp_Folder/TestLog/ /mnt/c/<Application>/Logs. - I started up my application.
I did not see any logs appearing in the directory C:\Temp_Folder\TestLog\.
I see different reasons:
- Either it’s a complete stupid idea to try to use Linux technology on a Windows computer.
- Either it might work, but some extra things need to be taken into account.
I hope it’s the second choice, but in that case, what things do I need to take into account?
Edit after Harry‘s answer:
Why use WSL’s ln -s if you can use Windows technology, like mklink? 🙂
C:\<Runtime_Dir>mklink /D Logs E:\TestLog\
=> result:
29/03/2024 08:21 <SYMLINKD> Logs [E:\TestLog\]=> So, indeed, the Logs directory symlink is created, but when I launch my application, it seems not to write any logs anymore (I see them being created in a console window, but they are not written down in a file).
Some other experiments: (I remember something about a junction from before, but the details have slipped my mind)
C:\<Runtime_Dir>mklink /D /J Logs E:\TestLog\
Local volumes are required to complete the operation.C:\<Runtime_Dir>mklink /D /H Logs E:\TestLog\
The system cannot find the path specified.C:\<Runtime_Dir>mklink /J Logs E:\TestLog\
Local volumes are required to complete the operation.Edit2 after some more experiments:
It seems not to work, while referring to another drive, but it does seem to work when I refer to another directory on the same computer, as you can see here:
C:\<Runtime_Dir>mklink /D Logs C:\Temp_Folder\TestLog\
symbolic link created for Logs <<===>> C:\Temp_Folder\TestLog\
C:\<Runtime_Dir>mklink /D /J Logs C:\Temp_Folder\TestLog\
Junction created for Logs <<===>> C:\Temp_Folder\TestLog\I can confirm that, in both cases, the logs are being created!
In other words, the problem is not that the Windows symlink/junction is not working: the problem is with the fact that the symlink/junction is referring to another drive.
I remember that there are two, even three ways to create a drive in Windows (a drive mapping, a subst (?) and another one(???), this is all very blurry in my head), and I’m wondering whether the symlink/junction story might be working on one kind of drive, but not the other, and if there is a way to work around this.
Edit3 after the answer of u1686_gravity:
Even when using UNC path and having the “correct” configured behaviour, it still seems not to work:
fsutil behavior query symlinkEvaluation
Local to local symbolic links are enabled.
Local to remote symbolic links are enabled. => That's the one, isn't it?
Remote to local symbolic links are disabled.
Remote to remote symbolic links are disabled.C:\<Runtime_Dir>mklink /D Logs \\petrvs01\Log\TestLog\
symbolic link created for Logs <<===>> \\petrvs01\Log\TestLog\The link gets created, but no logfiles are being created over there.

I have learned three things up to now:
- For creating a symlink on Windows, use
mklinkinstead of WSL’sln -s. Open a command prompt as an administrator for this. - For creating a symlink/junction to a remote directory, you need to use the UNC path, not the drive letter.
- Permission for creating symlinks/junctions from and to remote directories is checked, using the
fsutilcommandfsutil behavior query symlinkEvaluation.
Next thing I need to learn: where to check for the symlink/junction destination permissions? Does anybody have an idea?




