80

Is there a way to see a list of all the symbolic links that are active on a Windows machine?

26

In PowerShell

Get-ChildItem -Path C:\ -Force -Recurse -ErrorAction 'silentlycontinue' | 
  Where { $_.Attributes -match "ReparsePoint"}
  • -Force includes hidden and system files
  • -Recurse gets all child items
  • -ErrorAction 'silentlycontinue' suppresses Access to the path XYZ is denied errors
  • Where { $_.Attributes -match "ReparsePoint"} checks folders and files if it's a junction

Explanation of Mode and Attributes:

PS > GCI | SELECT Mode,Attribuets -Unique

Mode                    Attributes
----                    ----------
d----                    Directory
d---s            System, Directory
d---- Directory, NotContentIndexed
d----        Directory, Compressed
la---                      Archive
-a---                      Archive
lar--            ReadOnly, Archive
-a---          Archive, Compressed
4
  • 1
    Thanks -- this could be really powerful for scripting -- is there a property that displays where the link goes to? -- it doesn't seem to be displayed by default, but if it's there we could script against it and that would be awesome. – BrainSlugs83 Oct 12 '14 at 1:11
  • 2
    @BrainSlugs83 To get the target of ReparsePoints programmatically , read this SO answer – nixda Dec 4 '14 at 23:38
  • How to just get the ones create by the current user and not the OS? – boardtc Jan 15 '20 at 17:14
  • Thanks, I think your answer is more self-documenting now. If Dir = GCI please add it back. – Louis Waweru Sep 19 '20 at 5:42
115

Try the following command:

dir /AL /S C:\
  • /A displays all files with a specific attribute, and L specifies reparse points (symlinks and directory junctions)
  • /S makes the command recursive
  • replace C:\ with the drive letter you want to scan, or with a path if you don't want to scan an entire drive
1
  • 7
    Is there a way to make it not recurse into symlinks / junctions so that it doesn't get stuck in an infinite loop? – BrainSlugs83 Oct 12 '14 at 1:09
12

There's also a handy program for that called NTFSLinksView.

Edit: there's also SageLinks, this one checks the validity too.

1
  • NirSoft strikes again! After downloading NirCmd, I was overwhelmed with the other stuff he had and figured I should just be grateful he had NirCmd. – aschultz Nov 26 '20 at 9:03
3

I know this answer is late, but here's perhaps something closer to what you were probably looking for:

dir /AL /S C:\ | find "SYMLINK"
4
  • 1
    Of course this will also show files and directories that have SYMLINK in their name. – Scott Sep 25 '18 at 0:38
  • @Scott but if this is identical to the accepted answer, then all those folders regardless of their name will be symbolic links. – Mark C Apr 17 '20 at 7:42
  • @MarkC: Ah, in my haste to comment (over 1½ years ago), I failed to notice that this was Indrek’s answer plus a garnish, and I failed to register the /AL.  Still, Indrek’s answer explains that /AL specifies listing reparse points (which include symlinks and directory junctions), and so it becomes a question of definitions.  If you (IMHO, incorrectly) consider directory junctions to be a type of symlink, then this answer is wrong because it filters out directory junctions like Local Settings, My Documents and My Pictures.  … (Cont’d) – Scott Apr 17 '20 at 17:13
  • 1
    (Cont’d) …  If you consider directory junctions not to be a type of symlink, then this answer is wrong because it shows directory junctions that have SYMLINK in their name. (And it can be fixed just by changing it to find "<SYMLINK".) – Scott Apr 17 '20 at 17:13
1

$_.Linktype misses Symlinks. $_.Attributes misses Hardlinks. Junctions are listed in both properties. -Force is needed else hidden symlinks are skipped. Full working example which gets symlinks, junctions and hardlinks:

Get-ChildItem -Path "C:\Windows\","c:\","$env:USERPROFILE" -Force |
    Where-Object { $_.LinkType -ne $null -or $_.Attributes -match "ReparsePoint" } |
    ft FullName,Length,Attributes,Linktype,Target

The output looks like this - in my case I made a junction just to show how it should look like. Be aware: PS still has a bug not showing the target of Symlinks, check this for more information: https://stackoverflow.com/questions/16926127/powershell-to-resolve-junction-target-path

PS D:\> Get-ChildItem -Path "C:\Windows\","c:\","$env:USERPROFILE" -Force |
    Where-Object { $_.LinkType -ne $null -or $_.Attributes -match "ReparsePoint" } |
    ft FullName,Length,Attributes,Linktype,Target


FullName                                     Length                                                 Attributes LinkType Target                                                                                                  
--------                                     ------                                                 ---------- -------- ------                                                                                                  
C:\Windows\bfsvc.exe                          79360                                                    Archive HardLink {C:\Windows\WinSxS\amd64_microsoft-windows-b..vironment-servicing_31bf3856ad364e35_10.0.17763.1518_no...
C:\Windows\DfsrAdmin.exe                     232960                                                    Archive HardLink {C:\Windows\WinSxS\msil_dfsradmin_31bf3856ad364e35_10.0.17763.529_none_86a482ce47ce0e6b\DfsrAdmin.exe...
C:\Windows\explorer.exe                     4389168                                                    Archive HardLink {C:\Windows\WinSxS\amd64_microsoft-windows-explorer_31bf3856ad364e35_10.0.17763.1911_none_9f01b4994bb...
C:\Windows\HelpPane.exe                     1072128                                                    Archive HardLink {C:\Windows\WinSxS\amd64_microsoft-windows-help-client_31bf3856ad364e35_10.0.17763.1911_none_b9659da9...
C:\Windows\hh.exe                             18432                                                    Archive HardLink {C:\Windows\WinSxS\amd64_microsoft-windows-htmlhelp_31bf3856ad364e35_10.0.17763.1697_none_15caed9d569...
C:\Windows\mib.bin                            43131                                                    Archive HardLink {C:\Windows\WinSxS\amd64_microsoft-windows-snmp-mgmt-api_31bf3856ad364e35_10.0.17763.1_none_dc5249570...
C:\Windows\notepad.exe                       254464                                                    Archive HardLink {C:\Windows\WinSxS\amd64_microsoft-windows-notepad_31bf3856ad364e35_10.0.17763.1697_none_bc8f846641e0...
C:\Windows\regedit.exe                       357888                                                    Archive HardLink {C:\Windows\WinSxS\amd64_microsoft-windows-registry-editor_31bf3856ad364e35_10.0.17763.1697_none_41a3...
C:\Windows\splwow64.exe                      133632                                                    Archive HardLink {C:\Windows\WinSxS\amd64_microsoft-windows-printing-spooler-core_31bf3856ad364e35_10.0.17763.1697_non...
C:\Windows\twain_32.dll                       64512                                                    Archive HardLink {C:\Windows\WinSxS\wow64_microsoft-windows-w..ion-twaincomponents_31bf3856ad364e35_10.0.17763.1_none_...
C:\Windows\WindowsShell.Manifest                670                                  ReadOnly, Hidden, Archive HardLink {C:\Windows\WinSxS\amd64_microsoft-windows-shell32_31bf3856ad364e35_10.0.17763.1_none_5cef14c36a2559b...
C:\Windows\winhlp32.exe                       11776                                                    Archive HardLink {C:\Windows\WinSxS\wow64_microsoft-windows-winhstb_31bf3856ad364e35_10.0.17763.1_none_2420a29095f0ffc...
C:\Windows\WMSysPr9.prx                      316640                                                    Archive HardLink {C:\Windows\WinSxS\amd64_microsoft-windows-mediaplayer-wmvsdk_31bf3856ad364e35_10.0.17763.1_none_96f1...
C:\Windows\write.exe                          11264                                                    Archive HardLink {C:\Windows\WinSxS\amd64_microsoft-windows-write_31bf3856ad364e35_10.0.17763.1_none_5048bc153541494b\...
C:\BackupPlatte                                                                        Directory, ReparsePoint Junction {Volume{6072e7bc-2cae-11e9-b57a-bc5ff4e5c991}\}                                                         
C:\Dokumente und Einstellungen                      Hidden, System, Directory, ReparsePoint, NotContentIndexed                                                                                                                  
C:\Programme                                        Hidden, System, Directory, ReparsePoint, NotContentIndexed                                                                                                                  
C:\Users\Administrator\Anwendungsdaten              Hidden, System, Directory, ReparsePoint, NotContentIndexed                                                                                                                  
C:\Users\Administrator\Cookies                      Hidden, System, Directory, ReparsePoint, NotContentIndexed                                                                                                                  
C:\Users\Administrator\Druckumgebung                Hidden, System, Directory, ReparsePoint, NotContentIndexed                                                                                                                  
C:\Users\Administrator\Eigene Dateien               Hidden, System, Directory, ReparsePoint, NotContentIndexed                                                                                                                  
C:\Users\Administrator\Lokale Einstellungen         Hidden, System, Directory, ReparsePoint, NotContentIndexed                                                                                                                  
C:\Users\Administrator\Netzwerkumgebung             Hidden, System, Directory, ReparsePoint, NotContentIndexed                                                                                                                  
C:\Users\Administrator\Recent                       Hidden, System, Directory, ReparsePoint, NotContentIndexed                                                                                                                  
C:\Users\Administrator\SendTo                       Hidden, System, Directory, ReparsePoint, NotContentIndexed                                                                                                                  
C:\Users\Administrator\Startmenü                    Hidden, System, Directory, ReparsePoint, NotContentIndexed                                                                                                                  
C:\Users\Administrator\Vorlagen                     Hidden, System, Directory, ReparsePoint, NotContentIndexed            

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.