Quick Tip: Use PowerShell To Detect If A Location Is A Directory Or A Symlink

In PowerShell, symbolic links (symlinks) appear pretty transparently when you’re simply navigating the file system. If you’re doing other work, though, like changing ACLs, bumping into symlinks can be a pain. Here’s how to tell if a directory in question is a symlink or not.

Consider the following commands.

Here, we’re just running a Get-Item command on two locations, getting the Attributes property and converting to a string. The first item is a symlink and includes “ReparsePoint” in its attributes. The second item is a normal directory and does not include “ReparsePoint”.

So that means we can do something as easy as this.

Easy. If the above values have “ReparsePoint” in them, we know they are a symlink and not just a regular directory. In my case, my script to apply ACLs to a group of directories avoided symlinks with ease.

2 thoughts on “Quick Tip: Use PowerShell To Detect If A Location Is A Directory Or A Symlink

  1. Because Attributes is of type System.IO.FileAttributes, which is an enum type, it is better to use -band operator like so:

    (get-item c:\symlink).Attributes -band [IO.FileAttributes]::ReparsePoint

Comments are closed.