{"id":3131,"date":"2010-02-09T17:18:25","date_gmt":"2010-02-09T17:18:25","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/powershell\/2010\/02\/09\/viewing-junctions-with-dir\/"},"modified":"2019-02-18T13:05:59","modified_gmt":"2019-02-18T20:05:59","slug":"viewing-junctions-with-dir","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/powershell\/viewing-junctions-with-dir\/","title":{"rendered":"Viewing Junctions with \u2018dir\u2019"},"content":{"rendered":"<p>One feature of the NTFS file system is the junction, which is similar to a short cut but works at the file system level. This lets you link one directory to another. There\u2019s a tool called \u2018junction\u2019 available <a href=\"http:\/\/technet.microsoft.com\/en-us\/sysinternals\/bb896768.aspx\">here<\/a> that lets you manipulate junctions.<\/p>\n<p>When listing the contents of a directory, by default PowerShell doesn\u2019t tell you which sub-directories are junctions. I wanted to be able to tell which ones were junctions when doing a \u2018dir\u2019.<\/p>\n<p>The way I did that was to copy the built in file system formatting file, modify it so that junctions are indicated, then load it with Update-FormatData:<\/p>\n<p>The file system formatting rules are in $pshome\\FileSystem.Format.ps1xml. I copied this, then in the element [ViewDefinitions \u2013&gt; View \u2013&gt; TableControl \u2013&gt; TableRowEntries \u2013&gt; TableRowEntry \u2013&gt; TableColumnItems \u2013&gt; TableColumnItem] I changed the content of PropertyName with value of \u2018Mode\u2019 to the following:<\/p>\n<pre> &lt;ScriptBlock&gt; \n<br \/>&#160;&#160;&#160; &quot;$($_.Mode)$(if($_.Attributes -band [IO.FileAttributes]::ReparsePoint) {'J'})&quot;<br \/> &lt;\/ScriptBlock&gt; <\/pre>\n<div id=\"codeSnippetWrapper\">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 \u2018J\u2019 next to the other file mode attributes.<\/div>\n<p>Next, load the new formatting file like this:<\/p>\n<p>PS&gt; Update-FormatData -PrependPath myFilesystem.format.ps1xml<\/p>\n<p>The PrependPath parameter ensures that the new formatting file is loaded before the built-in formatting files.<\/p>\n<p>Let\u2019s see what the output looks like:<\/p>\n<div id=\"codeSnippetWrapper\">\n<pre id=\"codeSnippet\">PS&gt; dir<br \/><br \/>    Directory: C:\\tmp<br \/><br \/><br \/>Mode                LastWriteTime     Length Name<br \/>----                -------------     ------ ----<br \/>d----J         2\/9\/2010   3:51 PM            alink<br \/>d----          2\/9\/2010   3:51 PM            notAlink<\/pre>\n<p>Directory alink has a \u2018J\u2019 in the mode column, seems to work!<\/div>\n<p>cheers, Nigel Sharples [MSFT]<\/p>\n","protected":false},"excerpt":{"rendered":"<p>One feature of the NTFS file system is the junction, which is similar to a short cut but works at the file system level. This lets you link one directory to another. There\u2019s a tool called \u2018junction\u2019 available here that lets you manipulate junctions. When listing the contents of a directory, by default PowerShell doesn\u2019t [&hellip;]<\/p>\n","protected":false},"author":600,"featured_media":13641,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-3131","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-powershell"],"acf":[],"blog_post_summary":"<p>One feature of the NTFS file system is the junction, which is similar to a short cut but works at the file system level. This lets you link one directory to another. There\u2019s a tool called \u2018junction\u2019 available here that lets you manipulate junctions. When listing the contents of a directory, by default PowerShell doesn\u2019t [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts\/3131","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/users\/600"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/comments?post=3131"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts\/3131\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/media\/13641"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/media?parent=3131"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/categories?post=3131"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/tags?post=3131"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}