How can I test in PowerShell code if a folder is a junction point?
Take a look at this blog: https://web.archive.org/web/20190422210654/https://devblogs.microsoft.com/powershell/viewing-junctions-with-dir/
the way to do it is to copy the built in file system formatting file, modify it so that junctions are indicated, then load it with Update-FormatData:
From the Blog:
The file system formatting rules are in
$pshome\FileSystem.Format.ps1xml
. I copied this, then in the element[ViewDefinitions –> View –> TableControl –> TableRowEntries –> TableRowEntry –> TableColumnItems –> TableColumnItem]
I changed the content of PropertyName with value of 'Mode' to the following:<ScriptBlock> "$($_.Mode)$(if($_.Attributes -band [IO.FileAttributes]::ReparsePoint) {'J'})" </ScriptBlock>
This does a bitwise AND on the DirectoryInfo object Attributes property (
$_.Attributes
) against the .NetSystem.IO.FileAttributes.ReparsePoint
enum value. If the result is not zero, it displays a ‘J’ next to the other file mode attributes. Next, load the new formatting file like this:PS> Update-FormatData -PrependPath myFilesystem.format.ps1xml
The PrependPath parameter ensures that the new formatting file is loaded before the built-in formatting files.
Directory alink has a ‘J’ in the mode column, seems to work!
It's in the Mode column J for Junction.