How can I test in PowerShell code if a folder is a junction point?
Take a look at this blog: http://blogs.msdn.com/powershell/archive/2010/02/10/viewing-junctions-with-dir.aspx
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:
"$($.Mode)$(if($.Attributes -band [IO.FileAttributes]::ReparsePoint) {'J'})"
This does a bitwise AND on the DirectoryInfo object Attributes property ($_.Attributes) against the .Net System.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.
FYI, if you happen to be running PowerShell Community Extensions, this info is available as output (and as a note property) on output of Get-ChildItem:
21> gci .\Roaming\Microsoft\eHome
Directory: Microsoft.PowerShell.Core\FileSystem::C:\Users...
Mode LastWriteTime Length Name
---- ------------- ------ ----
d---- 2/15/2010 12:18 AM <DIR> DvdCoverCache
d---- 8/9/2009 1:10 AM <SYMLINK> DvdInfoCache [\...
d---- 8/8/2009 11:51 PM <DIR> DvdInfoCache.orig
d---- 10/22/2009 7:12 PM <DIR> mcl_images
However for programmatic access I would access the info via the Attributes property as the other poster suggests.