Test in PowerShell code if a folder is a junction point?

前端 未结 6 791
梦谈多话
梦谈多话 2021-01-13 00:30

How can I test in PowerShell code if a folder is a junction point?

6条回答
  •  情歌与酒
    2021-01-13 01:25

    Take a look at this blog: https://web.archive.org/web/20190422210654/https://devblogs.microsoft.com/powershell/viewing-junctions-with-dir/

    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.

提交回复
热议问题