

Quick Tip - Use PowerShell To Detect If A Location Is A Directory Or A Symlink
source link: https://thomasrayner.ca/quick-tip-use-powershell-to-detect-if-a-location-is-a-directory-or-a-symlink/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

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.
PS C:\Users\ThmsRynr> ((get-item c:\symlink).Attributes.ToString())
Directory, ReparsePoint
PS C:\Users\ThmsRynr> ((get-item c:\normaldir).Attributes.ToString())
Directory
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.
PS C:\Users\ThmsRynr> ((get-item c:\symlink).Attributes.ToString() -match "ReparsePoint")
True
PS C:\Users\ThmsRynr> ((get-item c:\normaldir).Attributes.ToString() -match "ReparsePoint")
False
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.
Recommend
-
21
Pilgo Overview Introduction Pilgo is a configuration-based dotfiles manager. That means it'll manage your dotfiles based on what's written in a configuration file, more specifically, a YAML file. It conta...
-
9
最近在使用 fs.symlink 实现软链时,发现文档里面写的是:fs.symlink(target, path);然而 man ln 的时候显示的是:ln s...
-
15
Quick Tip - See All The Tab-Completion Options At Once In The PowerShell Console If you’re used to working in VS Code or the PowerShell ISE, you’ve undoubtedly enjoyed intellisense which is the feature that shows you all...
-
20
Quick Tip - Split A PowerShell Collection Into Two Arrays Did you know that you can use Where-Object to split a collection into two arrays? Like, if you had an array containing the numbers 1 to 10, you c...
-
7
Quick Tip - PowerShell Supports Partial Parameter Names Did you know that PowerShell supports the usage of partial parameter names? This isn’t such a big deal since tab completion is a thing… and if you’re writing code,...
-
15
Quick Tip - Use PowerShell To See How Many Files Are In A Directory Here’s a way to see how many files are in a directory, using PowerShell. As you likely know, you can use Get-ChildItem to get...
-
10
Quick Tip - Diagnosing Slow PowerShell Load Times I could write an entire book on “why does my PowerShell console take so long to load?” but I don’t want to write that book. Instead, here’s a way to make sure the reason...
-
20
Quick Tip - Create New LPR Printers Using PowerShell There are a bunch of overloads for Add-Printer and Add-PrinterPort to accommodate different kinds of printers and ports. I found it t...
-
15
A quick PowerShell tip I have a bunch of PowerShell functions that I stick in my $profile file. Simple stuff, things to make my day to day development work easier. With my sieve-like memory, I need a quick way...
-
10
[Golang] Check if File, Directory, or Symlink Exist March 27, 2017
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK