From ed7282956a7c1dc1ebe4566f4b6fd557bd8c618d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Raimund=20And=C3=A9e?= Date: Fri, 30 Dec 2016 13:09:15 +0100 Subject: [PATCH] Added a property to find files with more than one hard link --- NTFSSecurity/ItemCmdlets/GetChildItem2.cs | 15 +++++++++++++++ NTFSSecurity/NTFSSecurity.psd1 | 1 + 2 files changed, 16 insertions(+) diff --git a/NTFSSecurity/ItemCmdlets/GetChildItem2.cs b/NTFSSecurity/ItemCmdlets/GetChildItem2.cs index 7548972..788c035 100644 --- a/NTFSSecurity/ItemCmdlets/GetChildItem2.cs +++ b/NTFSSecurity/ItemCmdlets/GetChildItem2.cs @@ -3,6 +3,7 @@ using System; using System.Collections; using System.Collections.Generic; using System.Management.Automation; +using System.Linq; namespace NTFSSecurity { @@ -22,6 +23,7 @@ namespace NTFSSecurity private SwitchParameter skipMountPoints; private SwitchParameter skipSymbolicLinks; private bool getFileSystemModeProperty = false; + private bool identifyHardLinks = false; private int? depth; WildcardPattern wildcard = null; @@ -139,6 +141,7 @@ namespace NTFSSecurity modeMethodInfo = typeof(FileSystemCodeMembers).GetMethod("Mode"); getFileSystemModeProperty = (bool)((Hashtable)MyInvocation.MyCommand.Module.PrivateData)["GetFileSystemModeProperty"]; + identifyHardLinks = (bool)((Hashtable)MyInvocation.MyCommand.Module.PrivateData)["IdentifyHardLinks"]; } protected override void ProcessRecord() @@ -303,6 +306,18 @@ namespace NTFSSecurity if (getFileSystemModeProperty) item.Properties.Add(new PSCodeProperty("Mode", modeMethodInfo)); + if (identifyHardLinks == true && current is FileInfo) + { + try + { + item.Properties.Add(new PSNoteProperty("HardLinkCount", Alphaleonis.Win32.Filesystem.File.EnumerateHardlinks(current.FullName).Count())); + } + catch + { + WriteDebug(string.Format("Could not read hard links for '{0}'", current.FullName)); + } + } + WriteObject(item); } } diff --git a/NTFSSecurity/NTFSSecurity.psd1 b/NTFSSecurity/NTFSSecurity.psd1 index ef53dc1..a9c80f7 100644 --- a/NTFSSecurity/NTFSSecurity.psd1 +++ b/NTFSSecurity/NTFSSecurity.psd1 @@ -87,6 +87,7 @@ GetInheritedFrom = $true GetFileSystemModeProperty = $true ShowAccountSid = $false + IdentifyHardLinks = $true PSData = @{ Tags = @('AccessControl', 'ACL', 'DirectorySecurity', 'FileSecurity', 'FileSystem', 'FileSystemSecurity', 'NTFS', 'Module', 'AccessRights')