├── .gitattributes ├── .github └── FUNDING.yml ├── .gitignore ├── .readthedocs.yml ├── Docs ├── Cmdlets │ ├── Add-NTFSAccess.md │ ├── Add-NTFSAudit.md │ ├── Clear-NTFSAccess.md │ ├── Clear-NTFSAudit.md │ ├── Copy-Item2.md │ ├── Disable-NTFSAccessInheritance.md │ ├── Disable-NTFSAuditInheritance.md │ ├── Disable-Privileges.md │ ├── Enable-NTFSAccessInheritance.md │ ├── Enable-NTFSAuditInheritance.md │ ├── Enable-Privileges.md │ ├── Get-ChildItem2.md │ ├── Get-DiskSpace.md │ ├── Get-FileHash2.md │ ├── Get-Item2.md │ ├── Get-NTFSAccess.md │ ├── Get-NTFSAudit.md │ ├── Get-NTFSEffectiveAccess.md │ ├── Get-NTFSHardLink.md │ ├── Get-NTFSInheritance.md │ ├── Get-NTFSOrphanedAccess.md │ ├── Get-NTFSOrphanedAudit.md │ ├── Get-NTFSOwner.md │ ├── Get-NTFSSecurityDescriptor.md │ ├── Get-NTFSSimpleAccess.md │ ├── Get-Privileges.md │ ├── Move-Item2.md │ ├── New-NTFSHardLink.md │ ├── New-NTFSSymbolicLink.md │ ├── Remove-Item2.md │ ├── Remove-NTFSAccess.md │ ├── Remove-NTFSAudit.md │ ├── Set-NTFSInheritance.md │ ├── Set-NTFSOwner.md │ ├── Set-NTFSSecurityDescriptor.md │ └── Test-Path2.md ├── Concepts.md ├── Contributing.md ├── Contributing │ ├── 01-Getting-Started.md │ ├── 02-Writing.md │ ├── 03-Style-Guide.md │ └── 04-Markdown-Specifics.md ├── Examples.md └── index.md ├── LICENSE ├── Log ├── Log.cs ├── Log.csproj └── Properties │ └── AssemblyInfo.cs ├── NTFSSecurity.sln ├── NTFSSecurity ├── AccessCmdlets │ ├── AddAccess.cs │ ├── ClearAccess.cs │ ├── GetAccess.cs │ ├── GetEffectiveAccess.cs │ ├── GetOrphanedAccess.cs │ └── RemoveAccess.cs ├── AuditCmdlets │ ├── AddAudit.cs │ ├── ClearAudit.cs │ ├── Get-OrphanedAudit.cs │ ├── GetAudit.cs │ └── RemoveAudit.cs ├── BaseCmdlets.cs ├── CodeMembers.cs ├── Extensions.cs ├── Help │ └── NTFSSecurity.Help.pshproj ├── InheritanceCmdlets │ ├── DisableAccessInheritance.cs │ ├── DisableAuditInheritance.cs │ ├── EnableAccessInheritance.cs │ ├── EnableAuditInheritance.cs │ ├── GetInheritance.cs │ └── SetInheritance.cs ├── ItemCmdlets │ ├── CopyItem2.cs │ ├── GetChildItem2.cs │ ├── GetDiskSpace.cs │ ├── GetItem2.cs │ ├── MoveItem2.cs │ └── RemoveItem2.cs ├── LinkCmdlets │ ├── GetHardLink.cs │ ├── NewHardLink.cs │ └── NewSymbolicLink.cs ├── MiscCmdlets │ └── GetFileHash2.cs ├── NTFSSecurity-Help.xml ├── NTFSSecurity.Init.ps1 ├── NTFSSecurity.csproj ├── NTFSSecurity.format.ps1xml ├── NTFSSecurity.psd1 ├── NTFSSecurity.psm1 ├── NTFSSecurity.types.ps1xml ├── OtherCmdlets.cs ├── OwnerCmdlets │ ├── GetOwner.cs │ └── SetOwner.cs ├── PathCmdlets │ └── TestPath2.cs ├── Properties │ ├── AssemblyInfo.cs │ ├── Resources.Designer.cs │ └── Resources.resx ├── Resources │ ├── IconContainer.bmp │ ├── User.jpg │ └── container.jpg ├── SecurityDescriptorCmdlets │ ├── GetSecurityDescriptor.cs │ └── SetSecurityDescriptor.cs ├── SimpleAccessCmdlets │ └── SimpleAccessCmdlets.cs └── packages.config ├── NTFSSecurityTest ├── IdentityReference2Tests.cs ├── NTFSSecurityTest.csproj ├── Properties │ ├── AssemblyInfo.cs │ ├── Settings.Designer.cs │ └── Settings.settings ├── UnitTest1.cs └── app.config ├── PrivilegeControl ├── PrivilegeControl.cs ├── PrivilegeControl.csproj └── Properties │ └── AssemblyInfo.cs ├── ProcessPrivileges ├── AccessTokenHandle.cs ├── AllocatedMemory.cs ├── Enums.cs ├── NativeEnums.cs ├── NativeMethods.cs ├── NativeStructs.cs ├── PrivilegeAndAttributes.cs ├── PrivilegeAndAttributesCollection.cs ├── PrivilegeEnabler.cs ├── Privileges.cs ├── ProcessExtensions.cs ├── ProcessHandle.cs ├── ProcessPrivileges.csproj └── Properties │ └── AssemblyInfo.cs ├── README.md ├── Security2 ├── EffectiveAccess.cs ├── Enums.cs ├── Exceptions │ └── Exceptions.cs ├── Extensions.cs ├── FileSystem │ ├── FileInfo │ │ └── Extensions.cs │ ├── FileSystemAccessRule2 Class │ │ ├── FileSystemAccessRule2.AddFileSystemAccessRules.cs │ │ ├── FileSystemAccessRule2.GetFileSystemAccessRules.cs │ │ ├── FileSystemAccessRule2.RemoveFileSystemAccessRules.cs │ │ ├── FileSystemAccessRule2.RemoveFileSystemAccessRulesAll.cs │ │ └── FileSystemAccessRule2.cs │ ├── FileSystemAuditRule2 Class │ │ ├── FileSystemAuditRule2.AddFileSystemAuditRules.cs │ │ ├── FileSystemAuditRule2.GetFileSystemAuditRules.cs │ │ ├── FileSystemAuditRule2.RemoveFileSystemAuditRule.cs │ │ ├── FileSystemAuditRule2.RemoveFileSystemAuditRuleAll.cs │ │ └── FileSystemAuditRule2.cs │ ├── FileSystemEffectivePermissionEntry.cs │ ├── FileSystemFlags.cs │ ├── FileSystemInheritanceInfo.cs │ ├── FileSystemOwner.cs │ ├── FileSystemSecurity2.cs │ ├── SimpleFileSystemAccessRule.cs │ └── SimpleFileSystemAuditRule.cs ├── IdentityReference2.cs ├── Properties │ └── AssemblyInfo.cs ├── Registry │ └── RegistrySecurity.cs ├── Security2.csproj ├── Win32 │ ├── Enums.cs │ ├── Errors.cs │ ├── Functions.cs │ ├── Lib.cs │ ├── SafeHandleEx.cs │ ├── Structs.cs │ ├── Win32Functions.cs │ └── Win32Lib.cs └── packages.config ├── TestClient ├── Program.cs ├── Properties │ └── AssemblyInfo.cs ├── TestClient.csproj ├── app.config └── packages.config ├── appveyor.yml └── mkdocs.yml /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: # raandree 4 | -------------------------------------------------------------------------------- /.readthedocs.yml: -------------------------------------------------------------------------------- 1 | # .readthedocs.yml 2 | # Read the Docs configuration file 3 | # See https://docs.readthedocs.io/en/stable/config-file/v2.html for details 4 | 5 | # Required 6 | version: 2 7 | 8 | # Build documentation with MkDocs 9 | mkdocs: 10 | configuration: mkdocs.yml 11 | 12 | # Optionally build your docs in additional formats such as PDF and ePub 13 | formats: all -------------------------------------------------------------------------------- /Docs/Cmdlets/Clear-NTFSAccess.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: NTFSSecurity.dll-Help.xml 3 | Module Name: ntfssecurity 4 | online version: 5 | schema: 2.0.0 6 | --- 7 | 8 | # Clear-NTFSAccess 9 | 10 | ## SYNOPSIS 11 | 12 | Removes all access control entries from a file or folder. 13 | 14 | ## SYNTAX 15 | 16 | ### Path (Default) 17 | ``` 18 | Clear-NTFSAccess [-Path] [-DisableInheritance] [] 19 | ``` 20 | 21 | ### SD 22 | ``` 23 | Clear-NTFSAccess [-SecurityDescriptor] [-DisableInheritance] [] 24 | ``` 25 | 26 | ## DESCRIPTION 27 | 28 | {{ Fill in the Description }} 29 | 30 | ## EXAMPLES 31 | 32 | ### Example 1 33 | 34 | ```PowerShell 35 | PS C:\> Clear-NTFSAccess -Path C:\Data\ -DisableInheritance 36 | ``` 37 | 38 | The above example would remove all access control entries from the folder C:\Data and disable inheritance on the folder as well. 39 | 40 | ## PARAMETERS 41 | 42 | ### -DisableInheritance 43 | 44 | The DisableInheritance parameter defines if you would like to didable the inheritance on the file or folder when clearing permissions. 45 | 46 | ```yaml 47 | Type: SwitchParameter 48 | Parameter Sets: (All) 49 | Aliases: 50 | 51 | Required: False 52 | Position: Named 53 | Default value: None 54 | Accept pipeline input: False 55 | Accept wildcard characters: False 56 | ``` 57 | 58 | ### -Path 59 | 60 | The Path parameter defines where the file or container exists to remove the access control entries from. 61 | 62 | ```yaml 63 | Type: String[] 64 | Parameter Sets: Path 65 | Aliases: FullName 66 | 67 | Required: True 68 | Position: 1 69 | Default value: None 70 | Accept pipeline input: True (ByPropertyName, ByValue) 71 | Accept wildcard characters: False 72 | ``` 73 | 74 | ### -SecurityDescriptor 75 | 76 | The SecurityDescriptor parameter allows passing an security descriptor or an array or security descriptors. 77 | 78 | A security descriptor contains information about the owner of the object, and the primary group of an object. The security descriptor also contains two access control lists (ACL). The first list is called the discretionary access control lists (DACL), and describes who should have access to an object and what type of access to grant. The second list is called the system access control lists (SACL) and defines what type of auditing to record for an object. 79 | 80 | ```yaml 81 | Type: FileSystemSecurity2[] 82 | Parameter Sets: SD 83 | Aliases: 84 | 85 | Required: True 86 | Position: 1 87 | Default value: None 88 | Accept pipeline input: True (ByPropertyName, ByValue) 89 | Accept wildcard characters: False 90 | ``` 91 | 92 | ### CommonParameters 93 | This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). 94 | 95 | ## INPUTS 96 | 97 | ### System.String[] 98 | 99 | ### Security2.FileSystemSecurity2[] 100 | 101 | ## OUTPUTS 102 | 103 | ### System.Object 104 | 105 | ## NOTES 106 | 107 | ## RELATED LINKS 108 | -------------------------------------------------------------------------------- /Docs/Cmdlets/Clear-NTFSAudit.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: NTFSSecurity.dll-Help.xml 3 | Module Name: ntfssecurity 4 | online version: 5 | schema: 2.0.0 6 | --- 7 | 8 | # Clear-NTFSAudit 9 | 10 | ## SYNOPSIS 11 | 12 | {{ Fill in the Synopsis }} 13 | 14 | ## SYNTAX 15 | 16 | ### Path (Default) 17 | ``` 18 | Clear-NTFSAudit [-Path] [-DisableInheritance] [] 19 | ``` 20 | 21 | ### SD 22 | ``` 23 | Clear-NTFSAudit [-SecurityDescriptor] [-DisableInheritance] [] 24 | ``` 25 | 26 | ## DESCRIPTION 27 | 28 | {{ Fill in the Description }} 29 | 30 | ## EXAMPLES 31 | 32 | ### Example 1 33 | 34 | ```PowerShell 35 | PS C:\> {{ Add example code here }} 36 | ``` 37 | 38 | {{ Add example description here }} 39 | 40 | ## PARAMETERS 41 | 42 | ### -DisableInheritance 43 | 44 | {{ Fill DisableInheritance Description }} 45 | 46 | ```yaml 47 | Type: SwitchParameter 48 | Parameter Sets: (All) 49 | Aliases: 50 | 51 | Required: False 52 | Position: Named 53 | Default value: None 54 | Accept pipeline input: False 55 | Accept wildcard characters: False 56 | ``` 57 | 58 | ### -Path 59 | 60 | {{ Fill Path Description }} 61 | 62 | ```yaml 63 | Type: String[] 64 | Parameter Sets: Path 65 | Aliases: FullName 66 | 67 | Required: True 68 | Position: 1 69 | Default value: None 70 | Accept pipeline input: True (ByPropertyName, ByValue) 71 | Accept wildcard characters: False 72 | ``` 73 | 74 | ### -SecurityDescriptor 75 | 76 | The SecurityDescriptor parameter allows passing an security descriptor or an array or security descriptors. 77 | 78 | A security descriptor contains information about the owner of the object, and the primary group of an object. The security descriptor also contains two access control lists (ACL). The first list is called the discretionary access control lists (DACL), and describes who should have access to an object and what type of access to grant. The second list is called the system access control lists (SACL) and defines what type of auditing to record for an object. 79 | 80 | ```yaml 81 | Type: FileSystemSecurity2[] 82 | Parameter Sets: SD 83 | Aliases: 84 | 85 | Required: True 86 | Position: 1 87 | Default value: None 88 | Accept pipeline input: True (ByPropertyName, ByValue) 89 | Accept wildcard characters: False 90 | ``` 91 | 92 | ### CommonParameters 93 | This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). 94 | 95 | ## INPUTS 96 | 97 | ### System.String[] 98 | 99 | ### Security2.FileSystemSecurity2[] 100 | 101 | ## OUTPUTS 102 | 103 | ### System.Object 104 | 105 | ## NOTES 106 | 107 | ## RELATED LINKS 108 | -------------------------------------------------------------------------------- /Docs/Cmdlets/Copy-Item2.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: NTFSSecurity.dll-Help.xml 3 | Module Name: ntfssecurity 4 | online version: 5 | schema: 2.0.0 6 | --- 7 | 8 | # Copy-Item2 9 | 10 | ## SYNOPSIS 11 | 12 | {{ Fill in the Synopsis }} 13 | 14 | ## SYNTAX 15 | 16 | ``` 17 | Copy-Item2 [-Path] [-Destination] [-Force] [-PassThru ] [-WhatIf] [-Confirm] 18 | [] 19 | ``` 20 | 21 | ## DESCRIPTION 22 | 23 | {{ Fill in the Description }} 24 | 25 | ## EXAMPLES 26 | 27 | ### Example 1 28 | 29 | ```PowerShell 30 | PS C:\> {{ Add example code here }} 31 | ``` 32 | 33 | {{ Add example description here }} 34 | 35 | ## PARAMETERS 36 | 37 | ### -Confirm 38 | 39 | Prompts you for confirmation before running the cmdlet. 40 | 41 | ```yaml 42 | Type: SwitchParameter 43 | Parameter Sets: (All) 44 | Aliases: cf 45 | 46 | Required: False 47 | Position: Named 48 | Default value: None 49 | Accept pipeline input: False 50 | Accept wildcard characters: False 51 | ``` 52 | 53 | ### -Destination 54 | 55 | {{ Fill Destination Description }} 56 | 57 | ```yaml 58 | Type: String 59 | Parameter Sets: (All) 60 | Aliases: 61 | 62 | Required: True 63 | Position: 2 64 | Default value: None 65 | Accept pipeline input: True (ByPropertyName) 66 | Accept wildcard characters: False 67 | ``` 68 | 69 | ### -Force 70 | 71 | {{ Fill Force Description }} 72 | 73 | ```yaml 74 | Type: SwitchParameter 75 | Parameter Sets: (All) 76 | Aliases: 77 | 78 | Required: False 79 | Position: Named 80 | Default value: None 81 | Accept pipeline input: False 82 | Accept wildcard characters: False 83 | ``` 84 | 85 | ### -PassThru 86 | 87 | {{ Fill PassThru Description }} 88 | 89 | ```yaml 90 | Type: Boolean 91 | Parameter Sets: (All) 92 | Aliases: 93 | 94 | Required: False 95 | Position: Named 96 | Default value: None 97 | Accept pipeline input: False 98 | Accept wildcard characters: False 99 | ``` 100 | 101 | ### -Path 102 | 103 | {{ Fill Path Description }} 104 | 105 | ```yaml 106 | Type: String[] 107 | Parameter Sets: (All) 108 | Aliases: FullName 109 | 110 | Required: True 111 | Position: 1 112 | Default value: None 113 | Accept pipeline input: True (ByPropertyName, ByValue) 114 | Accept wildcard characters: False 115 | ``` 116 | 117 | ### -WhatIf 118 | 119 | Shows what would happen if the cmdlet runs. 120 | The cmdlet is not run. 121 | 122 | ```yaml 123 | Type: SwitchParameter 124 | Parameter Sets: (All) 125 | Aliases: wi 126 | 127 | Required: False 128 | Position: Named 129 | Default value: None 130 | Accept pipeline input: False 131 | Accept wildcard characters: False 132 | ``` 133 | 134 | ### CommonParameters 135 | This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). 136 | 137 | ## INPUTS 138 | 139 | ### System.String[] 140 | 141 | ### System.String 142 | 143 | ## OUTPUTS 144 | 145 | ### System.Object 146 | 147 | ## NOTES 148 | 149 | ## RELATED LINKS 150 | -------------------------------------------------------------------------------- /Docs/Cmdlets/Disable-NTFSAccessInheritance.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: NTFSSecurity.dll-Help.xml 3 | Module Name: ntfssecurity 4 | online version: 5 | schema: 2.0.0 6 | --- 7 | 8 | # Disable-NTFSAccessInheritance 9 | 10 | ## SYNOPSIS 11 | 12 | {{ Fill in the Synopsis }} 13 | 14 | ## SYNTAX 15 | 16 | ### Path (Default) 17 | ``` 18 | Disable-NTFSAccessInheritance [[-Path] ] [-RemoveInheritedAccessRules] [-PassThru] 19 | [] 20 | ``` 21 | 22 | ### SecurityDescriptor 23 | ``` 24 | Disable-NTFSAccessInheritance [-SecurityDescriptor] [-RemoveInheritedAccessRules] 25 | [-PassThru] [] 26 | ``` 27 | 28 | ## DESCRIPTION 29 | 30 | {{ Fill in the Description }} 31 | 32 | ## EXAMPLES 33 | 34 | ### Example 1 35 | 36 | ```PowerShell 37 | PS C:\> {{ Add example code here }} 38 | ``` 39 | 40 | {{ Add example description here }} 41 | 42 | ## PARAMETERS 43 | 44 | ### -PassThru 45 | 46 | {{ Fill PassThru Description }} 47 | 48 | ```yaml 49 | Type: SwitchParameter 50 | Parameter Sets: (All) 51 | Aliases: 52 | 53 | Required: False 54 | Position: Named 55 | Default value: None 56 | Accept pipeline input: False 57 | Accept wildcard characters: False 58 | ``` 59 | 60 | ### -Path 61 | 62 | {{ Fill Path Description }} 63 | 64 | ```yaml 65 | Type: String[] 66 | Parameter Sets: Path 67 | Aliases: FullName 68 | 69 | Required: False 70 | Position: 1 71 | Default value: None 72 | Accept pipeline input: True (ByPropertyName, ByValue) 73 | Accept wildcard characters: False 74 | ``` 75 | 76 | ### -RemoveInheritedAccessRules 77 | 78 | {{ Fill RemoveInheritedAccessRules Description }} 79 | 80 | ```yaml 81 | Type: SwitchParameter 82 | Parameter Sets: (All) 83 | Aliases: 84 | 85 | Required: False 86 | Position: Named 87 | Default value: None 88 | Accept pipeline input: False 89 | Accept wildcard characters: False 90 | ``` 91 | 92 | ### -SecurityDescriptor 93 | 94 | The SecurityDescriptor parameter allows passing an security descriptor or an array or security descriptors. 95 | 96 | A security descriptor contains information about the owner of the object, and the primary group of an object. The security descriptor also contains two access control lists (ACL). The first list is called the discretionary access control lists (DACL), and describes who should have access to an object and what type of access to grant. The second list is called the system access control lists (SACL) and defines what type of auditing to record for an object. 97 | 98 | ```yaml 99 | Type: FileSystemSecurity2[] 100 | Parameter Sets: SecurityDescriptor 101 | Aliases: 102 | 103 | Required: True 104 | Position: 1 105 | Default value: None 106 | Accept pipeline input: True (ByPropertyName, ByValue) 107 | Accept wildcard characters: False 108 | ``` 109 | 110 | ### CommonParameters 111 | This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). 112 | 113 | ## INPUTS 114 | 115 | ### System.String[] 116 | 117 | ### Security2.FileSystemSecurity2[] 118 | 119 | ## OUTPUTS 120 | 121 | ### System.Object 122 | 123 | ## NOTES 124 | 125 | ## RELATED LINKS 126 | -------------------------------------------------------------------------------- /Docs/Cmdlets/Disable-NTFSAuditInheritance.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: NTFSSecurity.dll-Help.xml 3 | Module Name: ntfssecurity 4 | online version: 5 | schema: 2.0.0 6 | --- 7 | 8 | # Disable-NTFSAuditInheritance 9 | 10 | ## SYNOPSIS 11 | 12 | {{ Fill in the Synopsis }} 13 | 14 | ## SYNTAX 15 | 16 | ### Path (Default) 17 | ``` 18 | Disable-NTFSAuditInheritance [[-Path] ] [-RemoveInheritedAccessRules] [-PassThru] 19 | [] 20 | ``` 21 | 22 | ### SecurityDescriptor 23 | ``` 24 | Disable-NTFSAuditInheritance [-SecurityDescriptor] [-RemoveInheritedAccessRules] 25 | [-PassThru] [] 26 | ``` 27 | 28 | ## DESCRIPTION 29 | 30 | {{ Fill in the Description }} 31 | 32 | ## EXAMPLES 33 | 34 | ### Example 1 35 | 36 | ```PowerShell 37 | PS C:\> {{ Add example code here }} 38 | ``` 39 | 40 | {{ Add example description here }} 41 | 42 | ## PARAMETERS 43 | 44 | ### -PassThru 45 | 46 | {{ Fill PassThru Description }} 47 | 48 | ```yaml 49 | Type: SwitchParameter 50 | Parameter Sets: (All) 51 | Aliases: 52 | 53 | Required: False 54 | Position: Named 55 | Default value: None 56 | Accept pipeline input: False 57 | Accept wildcard characters: False 58 | ``` 59 | 60 | ### -Path 61 | 62 | {{ Fill Path Description }} 63 | 64 | ```yaml 65 | Type: String[] 66 | Parameter Sets: Path 67 | Aliases: FullName 68 | 69 | Required: False 70 | Position: 1 71 | Default value: None 72 | Accept pipeline input: True (ByPropertyName, ByValue) 73 | Accept wildcard characters: False 74 | ``` 75 | 76 | ### -RemoveInheritedAccessRules 77 | 78 | {{ Fill RemoveInheritedAccessRules Description }} 79 | 80 | ```yaml 81 | Type: SwitchParameter 82 | Parameter Sets: (All) 83 | Aliases: 84 | 85 | Required: False 86 | Position: Named 87 | Default value: None 88 | Accept pipeline input: False 89 | Accept wildcard characters: False 90 | ``` 91 | 92 | ### -SecurityDescriptor 93 | 94 | The SecurityDescriptor parameter allows passing an security descriptor or an array or security descriptors. 95 | 96 | A security descriptor contains information about the owner of the object, and the primary group of an object. The security descriptor also contains two access control lists (ACL). The first list is called the discretionary access control lists (DACL), and describes who should have access to an object and what type of access to grant. The second list is called the system access control lists (SACL) and defines what type of auditing to record for an object. 97 | 98 | ```yaml 99 | Type: FileSystemSecurity2[] 100 | Parameter Sets: SecurityDescriptor 101 | Aliases: 102 | 103 | Required: True 104 | Position: 1 105 | Default value: None 106 | Accept pipeline input: True (ByPropertyName, ByValue) 107 | Accept wildcard characters: False 108 | ``` 109 | 110 | ### CommonParameters 111 | This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). 112 | 113 | ## INPUTS 114 | 115 | ### System.String[] 116 | 117 | ### Security2.FileSystemSecurity2[] 118 | 119 | ## OUTPUTS 120 | 121 | ### System.Object 122 | 123 | ## NOTES 124 | 125 | ## RELATED LINKS 126 | -------------------------------------------------------------------------------- /Docs/Cmdlets/Disable-Privileges.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: NTFSSecurity.dll-Help.xml 3 | Module Name: ntfssecurity 4 | online version: 5 | schema: 2.0.0 6 | --- 7 | 8 | # Disable-Privileges 9 | 10 | ## SYNOPSIS 11 | 12 | {{ Fill in the Synopsis }} 13 | 14 | ## SYNTAX 15 | 16 | ``` 17 | Disable-Privileges [-PassThru] [] 18 | ``` 19 | 20 | ## DESCRIPTION 21 | 22 | {{ Fill in the Description }} 23 | 24 | ## EXAMPLES 25 | 26 | ### Example 1 27 | 28 | ```PowerShell 29 | PS C:\> {{ Add example code here }} 30 | ``` 31 | 32 | {{ Add example description here }} 33 | 34 | ## PARAMETERS 35 | 36 | ### -PassThru 37 | 38 | {{ Fill PassThru Description }} 39 | 40 | ```yaml 41 | Type: SwitchParameter 42 | Parameter Sets: (All) 43 | Aliases: 44 | 45 | Required: False 46 | Position: Named 47 | Default value: None 48 | Accept pipeline input: False 49 | Accept wildcard characters: False 50 | ``` 51 | 52 | ### CommonParameters 53 | This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). 54 | 55 | ## INPUTS 56 | 57 | ### None 58 | 59 | ## OUTPUTS 60 | 61 | ### ProcessPrivileges.PrivilegeAndAttributes 62 | 63 | ## NOTES 64 | 65 | ## RELATED LINKS 66 | -------------------------------------------------------------------------------- /Docs/Cmdlets/Enable-NTFSAccessInheritance.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: NTFSSecurity.dll-Help.xml 3 | Module Name: ntfssecurity 4 | online version: 5 | schema: 2.0.0 6 | --- 7 | 8 | # Enable-NTFSAccessInheritance 9 | 10 | ## SYNOPSIS 11 | 12 | {{ Fill in the Synopsis }} 13 | 14 | ## SYNTAX 15 | 16 | ### Path (Default) 17 | ``` 18 | Enable-NTFSAccessInheritance [[-Path] ] [-PassThru] [-RemoveExplicitAccessRules] [] 19 | ``` 20 | 21 | ### SecurityDescriptor 22 | ``` 23 | Enable-NTFSAccessInheritance [-SecurityDescriptor] [-PassThru] 24 | [-RemoveExplicitAccessRules] [] 25 | ``` 26 | 27 | ## DESCRIPTION 28 | 29 | {{ Fill in the Description }} 30 | 31 | ## EXAMPLES 32 | 33 | ### Example 1 34 | 35 | ```PowerShell 36 | PS C:\> {{ Add example code here }} 37 | ``` 38 | 39 | {{ Add example description here }} 40 | 41 | ## PARAMETERS 42 | 43 | ### -PassThru 44 | 45 | {{ Fill PassThru Description }} 46 | 47 | ```yaml 48 | Type: SwitchParameter 49 | Parameter Sets: (All) 50 | Aliases: 51 | 52 | Required: False 53 | Position: Named 54 | Default value: None 55 | Accept pipeline input: False 56 | Accept wildcard characters: False 57 | ``` 58 | 59 | ### -Path 60 | 61 | {{ Fill Path Description }} 62 | 63 | ```yaml 64 | Type: String[] 65 | Parameter Sets: Path 66 | Aliases: FullName 67 | 68 | Required: False 69 | Position: 1 70 | Default value: None 71 | Accept pipeline input: True (ByPropertyName, ByValue) 72 | Accept wildcard characters: False 73 | ``` 74 | 75 | ### -RemoveExplicitAccessRules 76 | 77 | {{ Fill RemoveExplicitAccessRules Description }} 78 | 79 | ```yaml 80 | Type: SwitchParameter 81 | Parameter Sets: (All) 82 | Aliases: 83 | 84 | Required: False 85 | Position: Named 86 | Default value: None 87 | Accept pipeline input: False 88 | Accept wildcard characters: False 89 | ``` 90 | 91 | ### -SecurityDescriptor 92 | 93 | The SecurityDescriptor parameter allows passing an security descriptor or an array or security descriptors. 94 | 95 | A security descriptor contains information about the owner of the object, and the primary group of an object. The security descriptor also contains two access control lists (ACL). The first list is called the discretionary access control lists (DACL), and describes who should have access to an object and what type of access to grant. The second list is called the system access control lists (SACL) and defines what type of auditing to record for an object. 96 | 97 | ```yaml 98 | Type: FileSystemSecurity2[] 99 | Parameter Sets: SecurityDescriptor 100 | Aliases: 101 | 102 | Required: True 103 | Position: 1 104 | Default value: None 105 | Accept pipeline input: True (ByPropertyName, ByValue) 106 | Accept wildcard characters: False 107 | ``` 108 | 109 | ### CommonParameters 110 | This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). 111 | 112 | ## INPUTS 113 | 114 | ### System.String[] 115 | 116 | ### Security2.FileSystemSecurity2[] 117 | 118 | ## OUTPUTS 119 | 120 | ### System.Object 121 | 122 | ## NOTES 123 | 124 | ## RELATED LINKS 125 | -------------------------------------------------------------------------------- /Docs/Cmdlets/Enable-NTFSAuditInheritance.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: NTFSSecurity.dll-Help.xml 3 | Module Name: ntfssecurity 4 | online version: 5 | schema: 2.0.0 6 | --- 7 | 8 | # Enable-NTFSAuditInheritance 9 | 10 | ## SYNOPSIS 11 | 12 | {{ Fill in the Synopsis }} 13 | 14 | ## SYNTAX 15 | 16 | ### Path (Default) 17 | ``` 18 | Enable-NTFSAuditInheritance [[-Path] ] [-PassThru] [-RemoveExplicitAccessRules] [] 19 | ``` 20 | 21 | ### SecurityDescriptor 22 | ``` 23 | Enable-NTFSAuditInheritance [-SecurityDescriptor] [-PassThru] 24 | [-RemoveExplicitAccessRules] [] 25 | ``` 26 | 27 | ## DESCRIPTION 28 | 29 | {{ Fill in the Description }} 30 | 31 | ## EXAMPLES 32 | 33 | ### Example 1 34 | 35 | ```PowerShell 36 | PS C:\> {{ Add example code here }} 37 | ``` 38 | 39 | {{ Add example description here }} 40 | 41 | ## PARAMETERS 42 | 43 | ### -PassThru 44 | 45 | {{ Fill PassThru Description }} 46 | 47 | ```yaml 48 | Type: SwitchParameter 49 | Parameter Sets: (All) 50 | Aliases: 51 | 52 | Required: False 53 | Position: Named 54 | Default value: None 55 | Accept pipeline input: False 56 | Accept wildcard characters: False 57 | ``` 58 | 59 | ### -Path 60 | 61 | {{ Fill Path Description }} 62 | 63 | ```yaml 64 | Type: String[] 65 | Parameter Sets: Path 66 | Aliases: FullName 67 | 68 | Required: False 69 | Position: 1 70 | Default value: None 71 | Accept pipeline input: True (ByPropertyName, ByValue) 72 | Accept wildcard characters: False 73 | ``` 74 | 75 | ### -RemoveExplicitAccessRules 76 | 77 | {{ Fill RemoveExplicitAccessRules Description }} 78 | 79 | ```yaml 80 | Type: SwitchParameter 81 | Parameter Sets: (All) 82 | Aliases: 83 | 84 | Required: False 85 | Position: Named 86 | Default value: None 87 | Accept pipeline input: False 88 | Accept wildcard characters: False 89 | ``` 90 | 91 | ### -SecurityDescriptor 92 | 93 | The SecurityDescriptor parameter allows passing an security descriptor or an array or security descriptors. 94 | 95 | A security descriptor contains information about the owner of the object, and the primary group of an object. The security descriptor also contains two access control lists (ACL). The first list is called the discretionary access control lists (DACL), and describes who should have access to an object and what type of access to grant. The second list is called the system access control lists (SACL) and defines what type of auditing to record for an object. 96 | 97 | ```yaml 98 | Type: FileSystemSecurity2[] 99 | Parameter Sets: SecurityDescriptor 100 | Aliases: 101 | 102 | Required: True 103 | Position: 1 104 | Default value: None 105 | Accept pipeline input: True (ByPropertyName, ByValue) 106 | Accept wildcard characters: False 107 | ``` 108 | 109 | ### CommonParameters 110 | This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). 111 | 112 | ## INPUTS 113 | 114 | ### System.String[] 115 | 116 | ### Security2.FileSystemSecurity2[] 117 | 118 | ## OUTPUTS 119 | 120 | ### System.Object 121 | 122 | ## NOTES 123 | 124 | ## RELATED LINKS 125 | -------------------------------------------------------------------------------- /Docs/Cmdlets/Enable-Privileges.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: NTFSSecurity.dll-Help.xml 3 | Module Name: ntfssecurity 4 | online version: 5 | schema: 2.0.0 6 | --- 7 | 8 | # Enable-Privileges 9 | 10 | ## SYNOPSIS 11 | 12 | {{ Fill in the Synopsis }} 13 | 14 | ## SYNTAX 15 | 16 | ``` 17 | Enable-Privileges [-PassThru] [] 18 | ``` 19 | 20 | ## DESCRIPTION 21 | 22 | {{ Fill in the Description }} 23 | 24 | ## EXAMPLES 25 | 26 | ### Example 1 27 | 28 | ```PowerShell 29 | PS C:\> {{ Add example code here }} 30 | ``` 31 | 32 | {{ Add example description here }} 33 | 34 | ## PARAMETERS 35 | 36 | ### -PassThru 37 | 38 | {{ Fill PassThru Description }} 39 | 40 | ```yaml 41 | Type: SwitchParameter 42 | Parameter Sets: (All) 43 | Aliases: 44 | 45 | Required: False 46 | Position: Named 47 | Default value: None 48 | Accept pipeline input: False 49 | Accept wildcard characters: False 50 | ``` 51 | 52 | ### CommonParameters 53 | This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). 54 | 55 | ## INPUTS 56 | 57 | ### None 58 | 59 | ## OUTPUTS 60 | 61 | ### ProcessPrivileges.PrivilegeAndAttributes 62 | 63 | ## NOTES 64 | 65 | ## RELATED LINKS 66 | -------------------------------------------------------------------------------- /Docs/Cmdlets/Get-DiskSpace.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: NTFSSecurity.dll-Help.xml 3 | Module Name: ntfssecurity 4 | online version: 5 | schema: 2.0.0 6 | --- 7 | 8 | # Get-DiskSpace 9 | 10 | ## SYNOPSIS 11 | 12 | {{ Fill in the Synopsis }} 13 | 14 | ## SYNTAX 15 | 16 | ``` 17 | Get-DiskSpace [[-DriveLetter] ] [] 18 | ``` 19 | 20 | ## DESCRIPTION 21 | 22 | {{ Fill in the Description }} 23 | 24 | ## EXAMPLES 25 | 26 | ### Example 1 27 | 28 | ```PowerShell 29 | PS C:\> {{ Add example code here }} 30 | ``` 31 | 32 | {{ Add example description here }} 33 | 34 | ## PARAMETERS 35 | 36 | ### -DriveLetter 37 | 38 | {{ Fill DriveLetter Description }} 39 | 40 | ```yaml 41 | Type: String[] 42 | Parameter Sets: (All) 43 | Aliases: 44 | 45 | Required: False 46 | Position: 1 47 | Default value: None 48 | Accept pipeline input: False 49 | Accept wildcard characters: False 50 | ``` 51 | 52 | ### CommonParameters 53 | This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). 54 | 55 | ## INPUTS 56 | 57 | ### None 58 | 59 | ## OUTPUTS 60 | 61 | ### Alphaleonis.Win32.Filesystem.DiskSpaceInfo 62 | 63 | ## NOTES 64 | 65 | ## RELATED LINKS 66 | -------------------------------------------------------------------------------- /Docs/Cmdlets/Get-FileHash2.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: NTFSSecurity.dll-Help.xml 3 | Module Name: ntfssecurity 4 | online version: 5 | schema: 2.0.0 6 | --- 7 | 8 | # Get-FileHash2 9 | 10 | ## SYNOPSIS 11 | 12 | {{ Fill in the Synopsis }} 13 | 14 | ## SYNTAX 15 | 16 | ``` 17 | Get-FileHash2 [-Path] [[-Algorithm] ] [] 18 | ``` 19 | 20 | ## DESCRIPTION 21 | 22 | {{ Fill in the Description }} 23 | 24 | ## EXAMPLES 25 | 26 | ### Example 1 27 | 28 | ```PowerShell 29 | PS C:\> {{ Add example code here }} 30 | ``` 31 | 32 | {{ Add example description here }} 33 | 34 | ## PARAMETERS 35 | 36 | ### -Algorithm 37 | 38 | {{ Fill Algorithm Description }} 39 | 40 | ```yaml 41 | Type: HashAlgorithms 42 | Parameter Sets: (All) 43 | Aliases: 44 | Accepted values: SHA1, SHA256, SHA384, SHA512, MACTripleDES, MD5, RIPEMD160 45 | 46 | Required: False 47 | Position: 2 48 | Default value: None 49 | Accept pipeline input: True (ByPropertyName) 50 | Accept wildcard characters: False 51 | ``` 52 | 53 | ### -Path 54 | 55 | {{ Fill Path Description }} 56 | 57 | ```yaml 58 | Type: String[] 59 | Parameter Sets: (All) 60 | Aliases: FullName 61 | 62 | Required: True 63 | Position: 1 64 | Default value: None 65 | Accept pipeline input: True (ByPropertyName, ByValue) 66 | Accept wildcard characters: False 67 | ``` 68 | 69 | ### CommonParameters 70 | This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). 71 | 72 | ## INPUTS 73 | 74 | ### System.String[] 75 | 76 | ### Security2.FileSystem.FileInfo.HashAlgorithms 77 | 78 | ## OUTPUTS 79 | 80 | ### Security2.FileSystemAccessRule2 81 | 82 | ## NOTES 83 | 84 | ## RELATED LINKS 85 | -------------------------------------------------------------------------------- /Docs/Cmdlets/Get-Item2.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: NTFSSecurity.dll-Help.xml 3 | Module Name: ntfssecurity 4 | online version: 5 | schema: 2.0.0 6 | --- 7 | 8 | # Get-Item2 9 | 10 | ## SYNOPSIS 11 | 12 | {{ Fill in the Synopsis }} 13 | 14 | ## SYNTAX 15 | 16 | ``` 17 | Get-Item2 [[-Path] ] [] 18 | ``` 19 | 20 | ## DESCRIPTION 21 | 22 | {{ Fill in the Description }} 23 | 24 | ## EXAMPLES 25 | 26 | ### Example 1 27 | 28 | ```PowerShell 29 | PS C:\> {{ Add example code here }} 30 | ``` 31 | 32 | {{ Add example description here }} 33 | 34 | ## PARAMETERS 35 | 36 | ### -Path 37 | 38 | {{ Fill Path Description }} 39 | 40 | ```yaml 41 | Type: String[] 42 | Parameter Sets: (All) 43 | Aliases: FullName 44 | 45 | Required: False 46 | Position: 1 47 | Default value: None 48 | Accept pipeline input: True (ByPropertyName, ByValue) 49 | Accept wildcard characters: False 50 | ``` 51 | 52 | ### CommonParameters 53 | This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). 54 | 55 | ## INPUTS 56 | 57 | ### System.String[] 58 | 59 | ## OUTPUTS 60 | 61 | ### Alphaleonis.Win32.Filesystem.FileInfo 62 | 63 | ### Alphaleonis.Win32.Filesystem.DirectoryInfo 64 | 65 | ## NOTES 66 | 67 | ## RELATED LINKS 68 | -------------------------------------------------------------------------------- /Docs/Cmdlets/Get-NTFSAccess.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: NTFSSecurity.dll-Help.xml 3 | Module Name: ntfssecurity 4 | online version: 5 | schema: 2.0.0 6 | --- 7 | 8 | # Get-NTFSAccess 9 | 10 | ## SYNOPSIS 11 | 12 | {{ Fill in the Synopsis }} 13 | 14 | ## SYNTAX 15 | 16 | ### Path (Default) 17 | ``` 18 | Get-NTFSAccess [[-Path] ] [-Account ] [-ExcludeExplicit] [-ExcludeInherited] 19 | [] 20 | ``` 21 | 22 | ### SD 23 | ``` 24 | Get-NTFSAccess [-SecurityDescriptor] [-Account ] [-ExcludeExplicit] 25 | [-ExcludeInherited] [] 26 | ``` 27 | 28 | ## DESCRIPTION 29 | 30 | {{ Fill in the Description }} 31 | 32 | ## EXAMPLES 33 | 34 | ### Example 1 35 | 36 | ```PowerShell 37 | PS C:\> {{ Add example code here }} 38 | ``` 39 | 40 | {{ Add example description here }} 41 | 42 | ## PARAMETERS 43 | 44 | ### -Account 45 | 46 | {{ Fill Account Description }} 47 | 48 | ```yaml 49 | Type: IdentityReference2 50 | Parameter Sets: (All) 51 | Aliases: IdentityReference, ID 52 | 53 | Required: False 54 | Position: Named 55 | Default value: None 56 | Accept pipeline input: False 57 | Accept wildcard characters: False 58 | ``` 59 | 60 | ### -ExcludeExplicit 61 | 62 | {{ Fill ExcludeExplicit Description }} 63 | 64 | ```yaml 65 | Type: SwitchParameter 66 | Parameter Sets: (All) 67 | Aliases: 68 | 69 | Required: False 70 | Position: Named 71 | Default value: None 72 | Accept pipeline input: False 73 | Accept wildcard characters: False 74 | ``` 75 | 76 | ### -ExcludeInherited 77 | 78 | {{ Fill ExcludeInherited Description }} 79 | 80 | ```yaml 81 | Type: SwitchParameter 82 | Parameter Sets: (All) 83 | Aliases: 84 | 85 | Required: False 86 | Position: Named 87 | Default value: None 88 | Accept pipeline input: False 89 | Accept wildcard characters: False 90 | ``` 91 | 92 | ### -Path 93 | 94 | {{ Fill Path Description }} 95 | 96 | ```yaml 97 | Type: String[] 98 | Parameter Sets: Path 99 | Aliases: FullName 100 | 101 | Required: False 102 | Position: 1 103 | Default value: None 104 | Accept pipeline input: True (ByPropertyName, ByValue) 105 | Accept wildcard characters: False 106 | ``` 107 | 108 | ### -SecurityDescriptor 109 | 110 | The SecurityDescriptor parameter allows passing an security descriptor or an array or security descriptors. 111 | 112 | A security descriptor contains information about the owner of the object, and the primary group of an object. The security descriptor also contains two access control lists (ACL). The first list is called the discretionary access control lists (DACL), and describes who should have access to an object and what type of access to grant. The second list is called the system access control lists (SACL) and defines what type of auditing to record for an object. 113 | 114 | ```yaml 115 | Type: FileSystemSecurity2[] 116 | Parameter Sets: SD 117 | Aliases: 118 | 119 | Required: True 120 | Position: 1 121 | Default value: None 122 | Accept pipeline input: True (ByPropertyName, ByValue) 123 | Accept wildcard characters: False 124 | ``` 125 | 126 | ### CommonParameters 127 | This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). 128 | 129 | ## INPUTS 130 | 131 | ### System.String[] 132 | 133 | ### Security2.FileSystemSecurity2[] 134 | 135 | ### Security2.IdentityReference2 136 | 137 | ## OUTPUTS 138 | 139 | ### Security2.FileSystemAccessRule2 140 | 141 | ## NOTES 142 | 143 | ## RELATED LINKS 144 | -------------------------------------------------------------------------------- /Docs/Cmdlets/Get-NTFSAudit.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: NTFSSecurity.dll-Help.xml 3 | Module Name: ntfssecurity 4 | online version: 5 | schema: 2.0.0 6 | --- 7 | 8 | # Get-NTFSAudit 9 | 10 | ## SYNOPSIS 11 | 12 | {{ Fill in the Synopsis }} 13 | 14 | ## SYNTAX 15 | 16 | ### Path 17 | ``` 18 | Get-NTFSAudit [[-Path] ] [-Account ] [-ExcludeExplicit] [-ExcludeInherited] 19 | [] 20 | ``` 21 | 22 | ### SD 23 | ``` 24 | Get-NTFSAudit [-SecurityDescriptor] [-Account ] [-ExcludeExplicit] 25 | [-ExcludeInherited] [] 26 | ``` 27 | 28 | ## DESCRIPTION 29 | 30 | {{ Fill in the Description }} 31 | 32 | ## EXAMPLES 33 | 34 | ### Example 1 35 | 36 | ```PowerShell 37 | PS C:\> {{ Add example code here }} 38 | ``` 39 | 40 | {{ Add example description here }} 41 | 42 | ## PARAMETERS 43 | 44 | ### -Account 45 | 46 | {{ Fill Account Description }} 47 | 48 | ```yaml 49 | Type: IdentityReference2 50 | Parameter Sets: (All) 51 | Aliases: IdentityReference, ID 52 | 53 | Required: False 54 | Position: Named 55 | Default value: None 56 | Accept pipeline input: False 57 | Accept wildcard characters: False 58 | ``` 59 | 60 | ### -ExcludeExplicit 61 | 62 | {{ Fill ExcludeExplicit Description }} 63 | 64 | ```yaml 65 | Type: SwitchParameter 66 | Parameter Sets: (All) 67 | Aliases: 68 | 69 | Required: False 70 | Position: Named 71 | Default value: None 72 | Accept pipeline input: False 73 | Accept wildcard characters: False 74 | ``` 75 | 76 | ### -ExcludeInherited 77 | 78 | {{ Fill ExcludeInherited Description }} 79 | 80 | ```yaml 81 | Type: SwitchParameter 82 | Parameter Sets: (All) 83 | Aliases: 84 | 85 | Required: False 86 | Position: Named 87 | Default value: None 88 | Accept pipeline input: False 89 | Accept wildcard characters: False 90 | ``` 91 | 92 | ### -Path 93 | 94 | {{ Fill Path Description }} 95 | 96 | ```yaml 97 | Type: String[] 98 | Parameter Sets: Path 99 | Aliases: FullName 100 | 101 | Required: False 102 | Position: 1 103 | Default value: None 104 | Accept pipeline input: True (ByPropertyName, ByValue) 105 | Accept wildcard characters: False 106 | ``` 107 | 108 | ### -SecurityDescriptor 109 | 110 | The SecurityDescriptor parameter allows passing an security descriptor or an array or security descriptors. 111 | 112 | A security descriptor contains information about the owner of the object, and the primary group of an object. The security descriptor also contains two access control lists (ACL). The first list is called the discretionary access control lists (DACL), and describes who should have access to an object and what type of access to grant. The second list is called the system access control lists (SACL) and defines what type of auditing to record for an object. 113 | 114 | ```yaml 115 | Type: FileSystemSecurity2[] 116 | Parameter Sets: SD 117 | Aliases: 118 | 119 | Required: True 120 | Position: 1 121 | Default value: None 122 | Accept pipeline input: True (ByPropertyName, ByValue) 123 | Accept wildcard characters: False 124 | ``` 125 | 126 | ### CommonParameters 127 | This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). 128 | 129 | ## INPUTS 130 | 131 | ### System.String[] 132 | 133 | ### Security2.FileSystemSecurity2[] 134 | 135 | ### Security2.IdentityReference2 136 | 137 | ## OUTPUTS 138 | 139 | ### Security2.FileSystemAuditRule2 140 | 141 | ## NOTES 142 | 143 | ## RELATED LINKS 144 | -------------------------------------------------------------------------------- /Docs/Cmdlets/Get-NTFSHardLink.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: NTFSSecurity.dll-Help.xml 3 | Module Name: ntfssecurity 4 | online version: 5 | schema: 2.0.0 6 | --- 7 | 8 | # Get-NTFSHardLink 9 | 10 | ## SYNOPSIS 11 | 12 | {{ Fill in the Synopsis }} 13 | 14 | ## SYNTAX 15 | 16 | ``` 17 | Get-NTFSHardLink [[-Path] ] [] 18 | ``` 19 | 20 | ## DESCRIPTION 21 | 22 | {{ Fill in the Description }} 23 | 24 | ## EXAMPLES 25 | 26 | ### Example 1 27 | 28 | ```PowerShell 29 | PS C:\> {{ Add example code here }} 30 | ``` 31 | 32 | {{ Add example description here }} 33 | 34 | ## PARAMETERS 35 | 36 | ### -Path 37 | 38 | {{ Fill Path Description }} 39 | 40 | ```yaml 41 | Type: String[] 42 | Parameter Sets: (All) 43 | Aliases: FullName 44 | 45 | Required: False 46 | Position: 1 47 | Default value: None 48 | Accept pipeline input: True (ByPropertyName, ByValue) 49 | Accept wildcard characters: False 50 | ``` 51 | 52 | ### CommonParameters 53 | This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). 54 | 55 | ## INPUTS 56 | 57 | ### System.String[] 58 | 59 | ## OUTPUTS 60 | 61 | ### Alphaleonis.Win32.Filesystem.FileInfo 62 | 63 | ### Alphaleonis.Win32.Filesystem.DirectoryInfo 64 | 65 | ## NOTES 66 | 67 | ## RELATED LINKS 68 | -------------------------------------------------------------------------------- /Docs/Cmdlets/Get-NTFSInheritance.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: NTFSSecurity.dll-Help.xml 3 | Module Name: ntfssecurity 4 | online version: 5 | schema: 2.0.0 6 | --- 7 | 8 | # Get-NTFSInheritance 9 | 10 | ## SYNOPSIS 11 | 12 | {{ Fill in the Synopsis }} 13 | 14 | ## SYNTAX 15 | 16 | ### Path (Default) 17 | ``` 18 | Get-NTFSInheritance [[-Path] ] [] 19 | ``` 20 | 21 | ### SecurityDescriptor 22 | ``` 23 | Get-NTFSInheritance [-SecurityDescriptor] [] 24 | ``` 25 | 26 | ## DESCRIPTION 27 | 28 | {{ Fill in the Description }} 29 | 30 | ## EXAMPLES 31 | 32 | ### Example 1 33 | 34 | ```PowerShell 35 | PS C:\> {{ Add example code here }} 36 | ``` 37 | 38 | {{ Add example description here }} 39 | 40 | ## PARAMETERS 41 | 42 | ### -Path 43 | 44 | {{ Fill Path Description }} 45 | 46 | ```yaml 47 | Type: String[] 48 | Parameter Sets: Path 49 | Aliases: FullName 50 | 51 | Required: False 52 | Position: 1 53 | Default value: None 54 | Accept pipeline input: True (ByPropertyName, ByValue) 55 | Accept wildcard characters: False 56 | ``` 57 | 58 | ### -SecurityDescriptor 59 | 60 | The SecurityDescriptor parameter allows passing an security descriptor or an array or security descriptors. 61 | 62 | A security descriptor contains information about the owner of the object, and the primary group of an object. The security descriptor also contains two access control lists (ACL). The first list is called the discretionary access control lists (DACL), and describes who should have access to an object and what type of access to grant. The second list is called the system access control lists (SACL) and defines what type of auditing to record for an object. 63 | 64 | ```yaml 65 | Type: FileSystemSecurity2[] 66 | Parameter Sets: SecurityDescriptor 67 | Aliases: 68 | 69 | Required: True 70 | Position: 1 71 | Default value: None 72 | Accept pipeline input: True (ByPropertyName, ByValue) 73 | Accept wildcard characters: False 74 | ``` 75 | 76 | ### CommonParameters 77 | This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). 78 | 79 | ## INPUTS 80 | 81 | ### System.String[] 82 | 83 | ### Security2.FileSystemSecurity2[] 84 | 85 | ## OUTPUTS 86 | 87 | ### Security2.FileSystemInheritanceInfo 88 | 89 | ## NOTES 90 | 91 | ## RELATED LINKS 92 | -------------------------------------------------------------------------------- /Docs/Cmdlets/Get-NTFSOrphanedAudit.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: NTFSSecurity.dll-Help.xml 3 | Module Name: ntfssecurity 4 | online version: 5 | schema: 2.0.0 6 | --- 7 | 8 | # Get-NTFSOrphanedAudit 9 | 10 | ## SYNOPSIS 11 | 12 | {{ Fill in the Synopsis }} 13 | 14 | ## SYNTAX 15 | 16 | ### Path 17 | ``` 18 | Get-NTFSOrphanedAudit [[-Path] ] [-Account ] [-ExcludeExplicit] 19 | [-ExcludeInherited] [] 20 | ``` 21 | 22 | ### SD 23 | ``` 24 | Get-NTFSOrphanedAudit [-SecurityDescriptor] [-Account ] 25 | [-ExcludeExplicit] [-ExcludeInherited] [] 26 | ``` 27 | 28 | ## DESCRIPTION 29 | 30 | {{ Fill in the Description }} 31 | 32 | ## EXAMPLES 33 | 34 | ### Example 1 35 | 36 | ```PowerShell 37 | PS C:\> {{ Add example code here }} 38 | ``` 39 | 40 | {{ Add example description here }} 41 | 42 | ## PARAMETERS 43 | 44 | ### -Account 45 | 46 | {{ Fill Account Description }} 47 | 48 | ```yaml 49 | Type: IdentityReference2 50 | Parameter Sets: (All) 51 | Aliases: IdentityReference, ID 52 | 53 | Required: False 54 | Position: Named 55 | Default value: None 56 | Accept pipeline input: False 57 | Accept wildcard characters: False 58 | ``` 59 | 60 | ### -ExcludeExplicit 61 | 62 | {{ Fill ExcludeExplicit Description }} 63 | 64 | ```yaml 65 | Type: SwitchParameter 66 | Parameter Sets: (All) 67 | Aliases: 68 | 69 | Required: False 70 | Position: Named 71 | Default value: None 72 | Accept pipeline input: False 73 | Accept wildcard characters: False 74 | ``` 75 | 76 | ### -ExcludeInherited 77 | 78 | {{ Fill ExcludeInherited Description }} 79 | 80 | ```yaml 81 | Type: SwitchParameter 82 | Parameter Sets: (All) 83 | Aliases: 84 | 85 | Required: False 86 | Position: Named 87 | Default value: None 88 | Accept pipeline input: False 89 | Accept wildcard characters: False 90 | ``` 91 | 92 | ### -Path 93 | 94 | {{ Fill Path Description }} 95 | 96 | ```yaml 97 | Type: String[] 98 | Parameter Sets: Path 99 | Aliases: FullName 100 | 101 | Required: False 102 | Position: 1 103 | Default value: None 104 | Accept pipeline input: True (ByPropertyName, ByValue) 105 | Accept wildcard characters: False 106 | ``` 107 | 108 | ### -SecurityDescriptor 109 | 110 | The SecurityDescriptor parameter allows passing an security descriptor or an array or security descriptors. 111 | 112 | A security descriptor contains information about the owner of the object, and the primary group of an object. The security descriptor also contains two access control lists (ACL). The first list is called the discretionary access control lists (DACL), and describes who should have access to an object and what type of access to grant. The second list is called the system access control lists (SACL) and defines what type of auditing to record for an object. 113 | 114 | ```yaml 115 | Type: FileSystemSecurity2[] 116 | Parameter Sets: SD 117 | Aliases: 118 | 119 | Required: True 120 | Position: 1 121 | Default value: None 122 | Accept pipeline input: True (ByPropertyName, ByValue) 123 | Accept wildcard characters: False 124 | ``` 125 | 126 | ### CommonParameters 127 | This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). 128 | 129 | ## INPUTS 130 | 131 | ### System.String[] 132 | 133 | ### Security2.FileSystemSecurity2[] 134 | 135 | ### Security2.IdentityReference2 136 | 137 | ## OUTPUTS 138 | 139 | ### Security2.FileSystemAuditRule2 140 | 141 | ## NOTES 142 | 143 | ## RELATED LINKS 144 | -------------------------------------------------------------------------------- /Docs/Cmdlets/Get-NTFSOwner.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: NTFSSecurity.dll-Help.xml 3 | Module Name: ntfssecurity 4 | online version: 5 | schema: 2.0.0 6 | --- 7 | 8 | # Get-NTFSOwner 9 | 10 | ## SYNOPSIS 11 | 12 | {{ Fill in the Synopsis }} 13 | 14 | ## SYNTAX 15 | 16 | ### Path (Default) 17 | ``` 18 | Get-NTFSOwner [[-Path] ] [] 19 | ``` 20 | 21 | ### SecurityDescriptor 22 | ``` 23 | Get-NTFSOwner [-SecurityDescriptor] [] 24 | ``` 25 | 26 | ## DESCRIPTION 27 | 28 | {{ Fill in the Description }} 29 | 30 | ## EXAMPLES 31 | 32 | ### Example 1 33 | 34 | ```PowerShell 35 | PS C:\> {{ Add example code here }} 36 | ``` 37 | 38 | {{ Add example description here }} 39 | 40 | ## PARAMETERS 41 | 42 | ### -Path 43 | 44 | {{ Fill Path Description }} 45 | 46 | ```yaml 47 | Type: String[] 48 | Parameter Sets: Path 49 | Aliases: FullName 50 | 51 | Required: False 52 | Position: 1 53 | Default value: None 54 | Accept pipeline input: True (ByPropertyName, ByValue) 55 | Accept wildcard characters: False 56 | ``` 57 | 58 | ### -SecurityDescriptor 59 | 60 | The SecurityDescriptor parameter allows passing an security descriptor or an array or security descriptors. 61 | 62 | A security descriptor contains information about the owner of the object, and the primary group of an object. The security descriptor also contains two access control lists (ACL). The first list is called the discretionary access control lists (DACL), and describes who should have access to an object and what type of access to grant. The second list is called the system access control lists (SACL) and defines what type of auditing to record for an object. 63 | 64 | ```yaml 65 | Type: FileSystemSecurity2[] 66 | Parameter Sets: SecurityDescriptor 67 | Aliases: 68 | 69 | Required: True 70 | Position: 1 71 | Default value: None 72 | Accept pipeline input: True (ByPropertyName, ByValue) 73 | Accept wildcard characters: False 74 | ``` 75 | 76 | ### CommonParameters 77 | This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). 78 | 79 | ## INPUTS 80 | 81 | ### System.String[] 82 | 83 | ### Security2.FileSystemSecurity2[] 84 | 85 | ## OUTPUTS 86 | 87 | ### Security2.FileSystemOwner 88 | 89 | ## NOTES 90 | 91 | ## RELATED LINKS 92 | -------------------------------------------------------------------------------- /Docs/Cmdlets/Get-NTFSSecurityDescriptor.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: NTFSSecurity.dll-Help.xml 3 | Module Name: ntfssecurity 4 | online version: 5 | schema: 2.0.0 6 | --- 7 | 8 | # Get-NTFSSecurityDescriptor 9 | 10 | ## SYNOPSIS 11 | 12 | {{ Fill in the Synopsis }} 13 | 14 | ## SYNTAX 15 | 16 | ``` 17 | Get-NTFSSecurityDescriptor [[-Path] ] [] 18 | ``` 19 | 20 | ## DESCRIPTION 21 | 22 | {{ Fill in the Description }} 23 | 24 | ## EXAMPLES 25 | 26 | ### Example 1 27 | 28 | ```PowerShell 29 | PS C:\> {{ Add example code here }} 30 | ``` 31 | 32 | {{ Add example description here }} 33 | 34 | ## PARAMETERS 35 | 36 | ### -Path 37 | 38 | {{ Fill Path Description }} 39 | 40 | ```yaml 41 | Type: String[] 42 | Parameter Sets: (All) 43 | Aliases: FullName 44 | 45 | Required: False 46 | Position: 1 47 | Default value: None 48 | Accept pipeline input: True (ByPropertyName, ByValue) 49 | Accept wildcard characters: False 50 | ``` 51 | 52 | ### CommonParameters 53 | This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). 54 | 55 | ## INPUTS 56 | 57 | ### System.String[] 58 | 59 | ## OUTPUTS 60 | 61 | ### Security2.FileSystemSecurity2 62 | 63 | ## NOTES 64 | 65 | ## RELATED LINKS 66 | -------------------------------------------------------------------------------- /Docs/Cmdlets/Get-Privileges.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: NTFSSecurity.dll-Help.xml 3 | Module Name: ntfssecurity 4 | online version: 5 | schema: 2.0.0 6 | --- 7 | 8 | # Get-Privileges 9 | 10 | ## SYNOPSIS 11 | 12 | {{ Fill in the Synopsis }} 13 | 14 | ## SYNTAX 15 | 16 | ``` 17 | Get-Privileges [] 18 | ``` 19 | 20 | ## DESCRIPTION 21 | 22 | {{ Fill in the Description }} 23 | 24 | ## EXAMPLES 25 | 26 | ### Example 1 27 | 28 | ```PowerShell 29 | PS C:\> Get-Privileges 30 | 31 | ------------------------------------------------------------------------- 32 | | Privilege | PrivilegeAttributes | PriviliegeState | 33 | |-------------------------------|---------------------|-----------------| 34 | | IncreaseQuota | Disabled | Disabled | 35 | | Security | Enabled | Enabled | 36 | | TakeOwnership | Enabled | Enabled | 37 | | LoadDriver | Disabled | Disabled | 38 | | SystemProfile | Disabled | Disabled | 39 | | SystemTime | Disabled | Disabled | 40 | | ProfileSingleProcess | Disabled | Disabled | 41 | | IncreaseBasePriority | Disabled | Disabled | 42 | | CreatePageFile | Disabled | Disabled | 43 | | Backup | Enabled | Enabled | 44 | | Restore | Enabled | Enabled | 45 | | Shutdown | Disabled | Disabled | 46 | | Debug | Enabled | Enabled | 47 | | SystemEnvironment | Disabled | Disabled | 48 | | ChangeNotify EnabledByDefault | Enabled | Enabled | 49 | | RemoteShutdown | Disabled | Disabled | 50 | | Undock | Disabled | Disabled | 51 | | ManageVolume | Disabled | Disabled | 52 | | Impersonate EnabledByDefault | Enabled | Enabled | 53 | | CreateGlobal EnabledByDefault | Enabled | Enabled | 54 | | IncreaseWorkingSet | Disabled | Disabled | 55 | | TimeZone | Disabled | Disabled | 56 | | CreateSymbolicLink | Disabled | Disabled | 57 | ------------------------------------------------------------------------- 58 | ``` 59 | 60 | The above command gets the privliges. 61 | 62 | ## PARAMETERS 63 | 64 | ### CommonParameters 65 | This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). 66 | 67 | ## INPUTS 68 | 69 | ### None 70 | 71 | ## OUTPUTS 72 | 73 | ### ProcessPrivileges.PrivilegeAndAttributes 74 | 75 | ## NOTES 76 | 77 | ## RELATED LINKS 78 | -------------------------------------------------------------------------------- /Docs/Cmdlets/Move-Item2.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: NTFSSecurity.dll-Help.xml 3 | Module Name: ntfssecurity 4 | online version: 5 | schema: 2.0.0 6 | --- 7 | 8 | # Move-Item2 9 | 10 | ## SYNOPSIS 11 | 12 | {{ Fill in the Synopsis }} 13 | 14 | ## SYNTAX 15 | 16 | ``` 17 | Move-Item2 [-Path] [-Destination] [-Force] [-PassThru ] [-WhatIf] [-Confirm] 18 | [] 19 | ``` 20 | 21 | ## DESCRIPTION 22 | 23 | {{ Fill in the Description }} 24 | 25 | ## EXAMPLES 26 | 27 | ### Example 1 28 | 29 | ```PowerShell 30 | PS C:\> {{ Add example code here }} 31 | ``` 32 | 33 | {{ Add example description here }} 34 | 35 | ## PARAMETERS 36 | 37 | ### -Confirm 38 | 39 | Prompts you for confirmation before running the cmdlet. 40 | 41 | ```yaml 42 | Type: SwitchParameter 43 | Parameter Sets: (All) 44 | Aliases: cf 45 | 46 | Required: False 47 | Position: Named 48 | Default value: None 49 | Accept pipeline input: False 50 | Accept wildcard characters: False 51 | ``` 52 | 53 | ### -Destination 54 | 55 | {{ Fill Destination Description }} 56 | 57 | ```yaml 58 | Type: String 59 | Parameter Sets: (All) 60 | Aliases: 61 | 62 | Required: True 63 | Position: 2 64 | Default value: None 65 | Accept pipeline input: True (ByPropertyName) 66 | Accept wildcard characters: False 67 | ``` 68 | 69 | ### -Force 70 | 71 | {{ Fill Force Description }} 72 | 73 | ```yaml 74 | Type: SwitchParameter 75 | Parameter Sets: (All) 76 | Aliases: 77 | 78 | Required: False 79 | Position: Named 80 | Default value: None 81 | Accept pipeline input: False 82 | Accept wildcard characters: False 83 | ``` 84 | 85 | ### -PassThru 86 | 87 | {{ Fill PassThru Description }} 88 | 89 | ```yaml 90 | Type: Boolean 91 | Parameter Sets: (All) 92 | Aliases: 93 | 94 | Required: False 95 | Position: Named 96 | Default value: None 97 | Accept pipeline input: False 98 | Accept wildcard characters: False 99 | ``` 100 | 101 | ### -Path 102 | 103 | {{ Fill Path Description }} 104 | 105 | ```yaml 106 | Type: String[] 107 | Parameter Sets: (All) 108 | Aliases: FullName 109 | 110 | Required: True 111 | Position: 1 112 | Default value: None 113 | Accept pipeline input: True (ByPropertyName, ByValue) 114 | Accept wildcard characters: False 115 | ``` 116 | 117 | ### -WhatIf 118 | 119 | Shows what would happen if the cmdlet runs. 120 | The cmdlet is not run. 121 | 122 | ```yaml 123 | Type: SwitchParameter 124 | Parameter Sets: (All) 125 | Aliases: wi 126 | 127 | Required: False 128 | Position: Named 129 | Default value: None 130 | Accept pipeline input: False 131 | Accept wildcard characters: False 132 | ``` 133 | 134 | ### CommonParameters 135 | This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). 136 | 137 | ## INPUTS 138 | 139 | ### System.String[] 140 | 141 | ### System.String 142 | 143 | ## OUTPUTS 144 | 145 | ### System.Object 146 | 147 | ## NOTES 148 | 149 | ## RELATED LINKS 150 | -------------------------------------------------------------------------------- /Docs/Cmdlets/New-NTFSHardLink.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: NTFSSecurity.dll-Help.xml 3 | Module Name: ntfssecurity 4 | online version: 5 | schema: 2.0.0 6 | --- 7 | 8 | # New-NTFSHardLink 9 | 10 | ## SYNOPSIS 11 | 12 | {{ Fill in the Synopsis }} 13 | 14 | ## SYNTAX 15 | 16 | ``` 17 | New-NTFSHardLink [[-Path] ] [[-Target] ] [-PassThru] [] 18 | ``` 19 | 20 | ## DESCRIPTION 21 | 22 | {{ Fill in the Description }} 23 | 24 | ## EXAMPLES 25 | 26 | ### Example 1 27 | 28 | ```PowerShell 29 | PS C:\> {{ Add example code here }} 30 | ``` 31 | 32 | {{ Add example description here }} 33 | 34 | ## PARAMETERS 35 | 36 | ### -PassThru 37 | 38 | {{ Fill PassThru Description }} 39 | 40 | ```yaml 41 | Type: SwitchParameter 42 | Parameter Sets: (All) 43 | Aliases: 44 | 45 | Required: False 46 | Position: Named 47 | Default value: None 48 | Accept pipeline input: False 49 | Accept wildcard characters: False 50 | ``` 51 | 52 | ### -Path 53 | 54 | {{ Fill Path Description }} 55 | 56 | ```yaml 57 | Type: String 58 | Parameter Sets: (All) 59 | Aliases: FullName 60 | 61 | Required: False 62 | Position: 1 63 | Default value: None 64 | Accept pipeline input: True (ByPropertyName, ByValue) 65 | Accept wildcard characters: False 66 | ``` 67 | 68 | ### -Target 69 | 70 | {{ Fill Target Description }} 71 | 72 | ```yaml 73 | Type: String 74 | Parameter Sets: (All) 75 | Aliases: 76 | 77 | Required: False 78 | Position: 2 79 | Default value: None 80 | Accept pipeline input: True (ByPropertyName, ByValue) 81 | Accept wildcard characters: False 82 | ``` 83 | 84 | ### CommonParameters 85 | This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). 86 | 87 | ## INPUTS 88 | 89 | ### System.String 90 | 91 | ## OUTPUTS 92 | 93 | ### Alphaleonis.Win32.Filesystem.FileInfo 94 | 95 | ### Alphaleonis.Win32.Filesystem.DirectoryInfo 96 | 97 | ## NOTES 98 | 99 | ## RELATED LINKS 100 | -------------------------------------------------------------------------------- /Docs/Cmdlets/New-NTFSSymbolicLink.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: NTFSSecurity.dll-Help.xml 3 | Module Name: ntfssecurity 4 | online version: 5 | schema: 2.0.0 6 | --- 7 | 8 | # New-NTFSSymbolicLink 9 | 10 | ## SYNOPSIS 11 | 12 | {{ Fill in the Synopsis }} 13 | 14 | ## SYNTAX 15 | 16 | ``` 17 | New-NTFSSymbolicLink [[-Path] ] [[-Target] ] [-PassThru] [] 18 | ``` 19 | 20 | ## DESCRIPTION 21 | 22 | {{ Fill in the Description }} 23 | 24 | ## EXAMPLES 25 | 26 | ### Example 1 27 | 28 | ```PowerShell 29 | PS C:\> {{ Add example code here }} 30 | ``` 31 | 32 | {{ Add example description here }} 33 | 34 | ## PARAMETERS 35 | 36 | ### -PassThru 37 | 38 | {{ Fill PassThru Description }} 39 | 40 | ```yaml 41 | Type: SwitchParameter 42 | Parameter Sets: (All) 43 | Aliases: 44 | 45 | Required: False 46 | Position: Named 47 | Default value: None 48 | Accept pipeline input: False 49 | Accept wildcard characters: False 50 | ``` 51 | 52 | ### -Path 53 | 54 | {{ Fill Path Description }} 55 | 56 | ```yaml 57 | Type: String 58 | Parameter Sets: (All) 59 | Aliases: FullName 60 | 61 | Required: False 62 | Position: 1 63 | Default value: None 64 | Accept pipeline input: True (ByPropertyName, ByValue) 65 | Accept wildcard characters: False 66 | ``` 67 | 68 | ### -Target 69 | 70 | {{ Fill Target Description }} 71 | 72 | ```yaml 73 | Type: String 74 | Parameter Sets: (All) 75 | Aliases: 76 | 77 | Required: False 78 | Position: 2 79 | Default value: None 80 | Accept pipeline input: True (ByPropertyName, ByValue) 81 | Accept wildcard characters: False 82 | ``` 83 | 84 | ### CommonParameters 85 | This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). 86 | 87 | ## INPUTS 88 | 89 | ### System.String 90 | 91 | ## OUTPUTS 92 | 93 | ### Alphaleonis.Win32.Filesystem.FileInfo 94 | 95 | ### Alphaleonis.Win32.Filesystem.DirectoryInfo 96 | 97 | ## NOTES 98 | 99 | ## RELATED LINKS 100 | -------------------------------------------------------------------------------- /Docs/Cmdlets/Remove-Item2.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: NTFSSecurity.dll-Help.xml 3 | Module Name: ntfssecurity 4 | online version: 5 | schema: 2.0.0 6 | --- 7 | 8 | # Remove-Item2 9 | 10 | ## SYNOPSIS 11 | 12 | {{ Fill in the Synopsis }} 13 | 14 | ## SYNTAX 15 | 16 | ``` 17 | Remove-Item2 [[-Path] ] [-Force] [-Recurse] [-PassThur] [-WhatIf] [-Confirm] [] 18 | ``` 19 | 20 | ## DESCRIPTION 21 | 22 | {{ Fill in the Description }} 23 | 24 | ## EXAMPLES 25 | 26 | ### Example 1 27 | 28 | ```PowerShell 29 | PS C:\> {{ Add example code here }} 30 | ``` 31 | 32 | {{ Add example description here }} 33 | 34 | ## PARAMETERS 35 | 36 | ### -Confirm 37 | 38 | Prompts you for confirmation before running the cmdlet. 39 | 40 | ```yaml 41 | Type: SwitchParameter 42 | Parameter Sets: (All) 43 | Aliases: cf 44 | 45 | Required: False 46 | Position: Named 47 | Default value: None 48 | Accept pipeline input: False 49 | Accept wildcard characters: False 50 | ``` 51 | 52 | ### -Force 53 | 54 | {{ Fill Force Description }} 55 | 56 | ```yaml 57 | Type: SwitchParameter 58 | Parameter Sets: (All) 59 | Aliases: 60 | 61 | Required: False 62 | Position: Named 63 | Default value: None 64 | Accept pipeline input: False 65 | Accept wildcard characters: False 66 | ``` 67 | 68 | ### -PassThur 69 | 70 | {{ Fill PassThur Description }} 71 | 72 | ```yaml 73 | Type: SwitchParameter 74 | Parameter Sets: (All) 75 | Aliases: 76 | 77 | Required: False 78 | Position: Named 79 | Default value: None 80 | Accept pipeline input: False 81 | Accept wildcard characters: False 82 | ``` 83 | 84 | ### -Path 85 | 86 | {{ Fill Path Description }} 87 | 88 | ```yaml 89 | Type: String[] 90 | Parameter Sets: (All) 91 | Aliases: FullName 92 | 93 | Required: False 94 | Position: 1 95 | Default value: None 96 | Accept pipeline input: True (ByPropertyName, ByValue) 97 | Accept wildcard characters: False 98 | ``` 99 | 100 | ### -Recurse 101 | 102 | {{ Fill Recurse Description }} 103 | 104 | ```yaml 105 | Type: SwitchParameter 106 | Parameter Sets: (All) 107 | Aliases: 108 | 109 | Required: False 110 | Position: Named 111 | Default value: None 112 | Accept pipeline input: False 113 | Accept wildcard characters: False 114 | ``` 115 | 116 | ### -WhatIf 117 | 118 | Shows what would happen if the cmdlet runs. 119 | The cmdlet is not run. 120 | 121 | ```yaml 122 | Type: SwitchParameter 123 | Parameter Sets: (All) 124 | Aliases: wi 125 | 126 | Required: False 127 | Position: Named 128 | Default value: None 129 | Accept pipeline input: False 130 | Accept wildcard characters: False 131 | ``` 132 | 133 | ### CommonParameters 134 | This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). 135 | 136 | ## INPUTS 137 | 138 | ### System.String[] 139 | 140 | ## OUTPUTS 141 | 142 | ### System.Object 143 | 144 | ## NOTES 145 | 146 | ## RELATED LINKS 147 | -------------------------------------------------------------------------------- /Docs/Cmdlets/Set-NTFSOwner.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: NTFSSecurity.dll-Help.xml 3 | Module Name: ntfssecurity 4 | online version: 5 | schema: 2.0.0 6 | --- 7 | 8 | # Set-NTFSOwner 9 | 10 | ## SYNOPSIS 11 | 12 | {{ Fill in the Synopsis }} 13 | 14 | ## SYNTAX 15 | 16 | ### Path (Default) 17 | ``` 18 | Set-NTFSOwner [[-Path] ] [-Account] [-PassThru] [] 19 | ``` 20 | 21 | ### SecurityDescriptor 22 | ``` 23 | Set-NTFSOwner [-SecurityDescriptor] [-Account] [-PassThru] 24 | [] 25 | ``` 26 | 27 | ## DESCRIPTION 28 | 29 | {{ Fill in the Description }} 30 | 31 | ## EXAMPLES 32 | 33 | ### Example 1 34 | 35 | ```PowerShell 36 | PS C:\> {{ Add example code here }} 37 | ``` 38 | 39 | {{ Add example description here }} 40 | 41 | ## PARAMETERS 42 | 43 | ### -Account 44 | 45 | {{ Fill Account Description }} 46 | 47 | ```yaml 48 | Type: IdentityReference2 49 | Parameter Sets: (All) 50 | Aliases: 51 | 52 | Required: True 53 | Position: 2 54 | Default value: None 55 | Accept pipeline input: True (ByPropertyName) 56 | Accept wildcard characters: False 57 | ``` 58 | 59 | ### -PassThru 60 | 61 | {{ Fill PassThru Description }} 62 | 63 | ```yaml 64 | Type: SwitchParameter 65 | Parameter Sets: (All) 66 | Aliases: 67 | 68 | Required: False 69 | Position: Named 70 | Default value: None 71 | Accept pipeline input: False 72 | Accept wildcard characters: False 73 | ``` 74 | 75 | ### -Path 76 | 77 | {{ Fill Path Description }} 78 | 79 | ```yaml 80 | Type: String[] 81 | Parameter Sets: Path 82 | Aliases: FullName 83 | 84 | Required: False 85 | Position: 1 86 | Default value: None 87 | Accept pipeline input: True (ByPropertyName, ByValue) 88 | Accept wildcard characters: False 89 | ``` 90 | 91 | ### -SecurityDescriptor 92 | 93 | The SecurityDescriptor parameter allows passing an security descriptor or an array or security descriptors. 94 | 95 | A security descriptor contains information about the owner of the object, and the primary group of an object. The security descriptor also contains two access control lists (ACL). The first list is called the discretionary access control lists (DACL), and describes who should have access to an object and what type of access to grant. The second list is called the system access control lists (SACL) and defines what type of auditing to record for an object. 96 | 97 | ```yaml 98 | Type: FileSystemSecurity2[] 99 | Parameter Sets: SecurityDescriptor 100 | Aliases: 101 | 102 | Required: True 103 | Position: 1 104 | Default value: None 105 | Accept pipeline input: True (ByPropertyName, ByValue) 106 | Accept wildcard characters: False 107 | ``` 108 | 109 | ### CommonParameters 110 | This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). 111 | 112 | ## INPUTS 113 | 114 | ### System.String[] 115 | 116 | ### Security2.FileSystemSecurity2[] 117 | 118 | ### Security2.IdentityReference2 119 | 120 | ## OUTPUTS 121 | 122 | ### Security2.FileSystemOwner 123 | 124 | ## NOTES 125 | 126 | ## RELATED LINKS 127 | -------------------------------------------------------------------------------- /Docs/Cmdlets/Set-NTFSSecurityDescriptor.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: NTFSSecurity.dll-Help.xml 3 | Module Name: ntfssecurity 4 | online version: 5 | schema: 2.0.0 6 | --- 7 | 8 | # Set-NTFSSecurityDescriptor 9 | 10 | ## SYNOPSIS 11 | 12 | {{ Fill in the Synopsis }} 13 | 14 | ## SYNTAX 15 | 16 | ``` 17 | Set-NTFSSecurityDescriptor [-SecurityDescriptor] [-PassThru] [] 18 | ``` 19 | 20 | ## DESCRIPTION 21 | 22 | {{ Fill in the Description }} 23 | 24 | ## EXAMPLES 25 | 26 | ### Example 1 27 | 28 | ```PowerShell 29 | PS C:\> {{ Add example code here }} 30 | ``` 31 | 32 | {{ Add example description here }} 33 | 34 | ## PARAMETERS 35 | 36 | ### -PassThru 37 | 38 | {{ Fill PassThru Description }} 39 | 40 | ```yaml 41 | Type: SwitchParameter 42 | Parameter Sets: (All) 43 | Aliases: 44 | 45 | Required: False 46 | Position: Named 47 | Default value: None 48 | Accept pipeline input: False 49 | Accept wildcard characters: False 50 | ``` 51 | 52 | ### -SecurityDescriptor 53 | 54 | The SecurityDescriptor parameter allows passing an security descriptor or an array or security descriptors. 55 | 56 | A security descriptor contains information about the owner of the object, and the primary group of an object. The security descriptor also contains two access control lists (ACL). The first list is called the discretionary access control lists (DACL), and describes who should have access to an object and what type of access to grant. The second list is called the system access control lists (SACL) and defines what type of auditing to record for an object. 57 | 58 | ```yaml 59 | Type: FileSystemSecurity2[] 60 | Parameter Sets: (All) 61 | Aliases: 62 | 63 | Required: True 64 | Position: 2 65 | Default value: None 66 | Accept pipeline input: True (ByPropertyName, ByValue) 67 | Accept wildcard characters: False 68 | ``` 69 | 70 | ### CommonParameters 71 | This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). 72 | 73 | ## INPUTS 74 | 75 | ### Security2.FileSystemSecurity2[] 76 | 77 | ## OUTPUTS 78 | 79 | ### Security2.FileSystemSecurity2 80 | 81 | ## NOTES 82 | 83 | ## RELATED LINKS 84 | -------------------------------------------------------------------------------- /Docs/Cmdlets/Test-Path2.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: NTFSSecurity.dll-Help.xml 3 | Module Name: ntfssecurity 4 | online version: 5 | schema: 2.0.0 6 | --- 7 | 8 | # Test-Path2 9 | 10 | ## SYNOPSIS 11 | 12 | {{ Fill in the Synopsis }} 13 | 14 | ## SYNTAX 15 | 16 | ``` 17 | Test-Path2 [-Path] [-PathType ] [] 18 | ``` 19 | 20 | ## DESCRIPTION 21 | 22 | {{ Fill in the Description }} 23 | 24 | ## EXAMPLES 25 | 26 | ### Example 1 27 | 28 | ```PowerShell 29 | PS C:\> {{ Add example code here }} 30 | ``` 31 | 32 | {{ Add example description here }} 33 | 34 | ## PARAMETERS 35 | 36 | ### -Path 37 | 38 | {{ Fill Path Description }} 39 | 40 | ```yaml 41 | Type: String[] 42 | Parameter Sets: (All) 43 | Aliases: FullName 44 | 45 | Required: True 46 | Position: 1 47 | Default value: None 48 | Accept pipeline input: True (ByPropertyName, ByValue) 49 | Accept wildcard characters: False 50 | ``` 51 | 52 | ### -PathType 53 | 54 | {{ Fill PathType Description }} 55 | 56 | ```yaml 57 | Type: TestPathType 58 | Parameter Sets: (All) 59 | Aliases: 60 | Accepted values: Any, Container, Leaf 61 | 62 | Required: False 63 | Position: Named 64 | Default value: None 65 | Accept pipeline input: True (ByPropertyName) 66 | Accept wildcard characters: False 67 | ``` 68 | 69 | ### CommonParameters 70 | This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). 71 | 72 | ## INPUTS 73 | 74 | ### System.String[] 75 | 76 | ### NTFSSecurity.TestPathType 77 | 78 | ## OUTPUTS 79 | 80 | ### Alphaleonis.Win32.Filesystem.FileInfo 81 | 82 | ### Alphaleonis.Win32.Filesystem.DirectoryInfo 83 | 84 | ## NOTES 85 | 86 | ## RELATED LINKS 87 | -------------------------------------------------------------------------------- /Docs/Contributing.md: -------------------------------------------------------------------------------- 1 | # Contributor Guide 2 | 3 | Thank you for your interest in contributing to quality documentations. 4 | As an open source project, we welcome input and updates from the community. 5 | The following topics explain how to contribute to the NTFSAccess documentation. 6 | 7 | 1. [Get started](./Contributing/01-Getting-Started.md) 8 | 2. [Writing PowerShell documentation](./Contributing/02-Writing.md) 9 | 10 | This contributor guide is a modified version of the one found on the [Powershell Docs](https://github.com/PowerShell/PowerShell-Docs) GitHub page. 11 | -------------------------------------------------------------------------------- /Docs/Contributing/01-Getting-Started.md: -------------------------------------------------------------------------------- 1 | # Contributing to PowerShell Documentation 2 | 3 | Thank you for your interest in NTFSAccess documentation! 4 | 5 | See below for details on how you can contribute to our technical documentation. 6 | 7 | > For general information about getting started with Git and GitHub, see [GitHub Help][git-help]. 8 | 9 | ## Providing feedback on NTFSAccess documentation 10 | 11 | Report errors, suggest changes, or request new topics by [creating an issue][new-issue] on the 12 | [NTFSAccess repository issues page][doc-issues]. 13 | 14 | ## Making minor edits to existing topics 15 | 16 | To [edit an existing file][edit-file], navigate to it and click the "Edit" button. GitHub will 17 | automatically create your own fork of our repository where you can make your changes. Once you are 18 | finished, save your edits and submit a [pull request][pull] to the *staging* branch of the 19 | [NTFSAccess-Docs][docs-repo] repository. After your pull request is created, someone on the 20 | NTFSAccess documentation team reviews your changes before merging them into the *staging* branch. 21 | 22 | ## Making major edits to existing topics 23 | 24 | If you are making significant changes, adding or changing images, or contributing a new article, you 25 | need to create a GitHub fork and clone it to your computer. A fork is a GitHub-based replica of the 26 | main repository, under your GitHub account, that provides you with a working copy which you can use 27 | in isolation. You create pull requests from your fork. Similarly, a clone is a local-based replica 28 | of the repository which, in this case, is a clone of your fork. The clone allows you to work on Git 29 | repositories offline, and using more powerful native software/tools. 30 | 31 | Here is the workflow for making major edits to existing documentation: 32 | 33 | 1. [Create a fork][fork] of the [NTFSAccess][docs-repo] repository. 34 | 2. [Create a clone of your fork][clone] on your local computer. 35 | 3. Create a new local branch in your cloned repository. 36 | 4. Make changes to the file(s) you want to update in a Markdown editor. 37 | 5. [Push your local branch][push] to your fork. 38 | 6. [Create a pull request][pull] to the *staging* branch of the [NTFSAccess-Docs][docs-repo] 39 | repository. 40 | 41 | ## Next steps 42 | 43 | See [Writing documentation](02-Writing.md). 44 | 45 | 46 | [git-help]: https://help.github.com/ 47 | [new-issue]: https://help.github.com/articles/creating-an-issue/ 48 | [doc-issues]: https://github.com/raandree/NTFSSecurity/issues 49 | [edit-file]: https://help.github.com/articles/editing-files-in-another-user-s-repository/ 50 | [docs-repo]: https://github.com/raandree/NTFSSecurity/ 51 | [fork]: https://help.github.com/articles/fork-a-repo/ 52 | [clone]: https://help.github.com/articles/cloning-a-repository/ 53 | [push]: https://help.github.com/articles/pushing-to-a-remote/ 54 | [pull]: https://help.github.com/articles/creating-a-pull-request/ -------------------------------------------------------------------------------- /Docs/Contributing/02-Writing.md: -------------------------------------------------------------------------------- 1 | # WRITING DOCUMENTATION 2 | 3 | One of the easiest ways to contribute to the NTFSAccess PowerShell module is by helping to write and edit documentation. 4 | All the documentation hosted on GitHub is written using *Markdown*. Markdown is a lightweight markup 5 | language with plain text formatting syntax. Markdown forms the basis of our documentation's 6 | conceptual authoring language. Creating new articles is as easy as writing a simple text file by 7 | using your favorite text editor. 8 | 9 | ## Markdown editors 10 | 11 | Here are some Markdown editors you can try out: 12 | 13 | - [Visual Studio Code](https://code.visualstudio.com) 14 | - [Atom](https://atom.io/) 15 | - [Sublime Text](http://www.sublimetext.com/) 16 | 17 | ## Get started using Markdown 18 | 19 | To get started using Markdown, see [How to use Markdown for writing Docs](https://docs.microsoft.com/contribute/how-to-write-use-markdown). 20 | 21 | NTFSSecurity uses the [Mkdocs][mkdocs] builder on ReadTheDocs for documentation. 22 | 23 | Don't use hard tabs in Markdown. For more detailed information about the Markdown specification, see the 24 | [Markdown Specifics](04-Markdown-Specifics.md) article. 25 | 26 | ## Creating new topics 27 | 28 | To contribute new documentation, check for issues tagged as ["Help Wanted"][labels] to make sure 29 | you're not duplicating efforts. If no one seems to be working on what you have planned: 30 | 31 | - Open a new issue and label it as "in progress". If you don't have rights to assign labels, add "in 32 | progress" as a comment to tell others what you're working on. 33 | - Follow the same workflow as described above for making major edits to existing topics. 34 | - Add your new article to the `TOC.yml` file (located in the top-level folder of each 35 | documentation set). 36 | 37 | ## Updating topics that exist in multiple versions 38 | 39 | Most reference topics are duplicated across all versions of PowerShell. When reporting an issue 40 | about a cmdlet reference or an About_ article, you must specify which versions are affected by the 41 | issue. The default issue template in GitHub includes a [GFM task list][gfm-task]. Use the checkboxes 42 | in the task list to specify which versions of the content are affected. When you submit a change to 43 | a article for an issue that affects multiple versions of the content, you must apply the appropriate 44 | change to each version of the file. 45 | 46 | ## Next Steps 47 | 48 | Read the [Style Guide](03-Style-Guide.md). 49 | 50 | 51 | [markdig]: https://github.com/lunet-io/markdig 52 | [CommonMark]: https://spec.commonmark.org/ 53 | [gfm-help]: https://help.github.com/categories/writing-on-github/ 54 | [labels]: https://github.com/raandree/NTFSSecurity/labels/Help%20Wanted 55 | [mkdocs]: https://www.mkdocs.org/user-guide/writing-your-docs/ -------------------------------------------------------------------------------- /Docs/Contributing/03-Style-Guide.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/raandree/NTFSSecurity/7a8a1a5347ef3336985b6c94f9193e11ef56b9af/Docs/Contributing/03-Style-Guide.md -------------------------------------------------------------------------------- /Docs/Contributing/04-Markdown-Specifics.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/raandree/NTFSSecurity/7a8a1a5347ef3336985b6c94f9193e11ef56b9af/Docs/Contributing/04-Markdown-Specifics.md -------------------------------------------------------------------------------- /Docs/index.md: -------------------------------------------------------------------------------- 1 | # NTFSSecurity 2 | 3 | [![Build status](https://ci.appveyor.com/api/projects/status/2gfb58t9qh655b8x?svg=true)](https://ci.appveyor.com/project/Sup3rlativ3/ntfssecurity) [![Documentation Status](https://readthedocs.org/projects/ntfssecurity/badge/?version=latest)](https://ntfssecurity.readthedocs.io/en/latest/?badge=latest) 4 | 5 | Managing file & folder permissions with PowerShell is only a bit easier than in VBS or the command line as there are no cmdlets for most day-to-day tasks like getting a permission report or adding permission to an item. PowerShell only offers Get-Acl and Set-Acl but everything in between getting and setting the ACL is missing. This module closes the gap. 6 | 7 | [Version History](https://github.com/raandree/NTFSSecurity/wiki/Version-History) 8 | 9 | ## Installation 10 | 11 | You have two options: 12 | 13 | * Download the latest release from the [releases](https://github.com/raandree/NTFSSecurity/releases) section on GitHub. 14 | * Download the module from the [PowerShell Gallery](https://www.powershellgallery.com/packages/NTFSSecurity): 15 | 16 | ```PowerShell 17 | Install-Module -Name NTFSSecurity 18 | ``` 19 | 20 | Further help can be found in How to install if you face difficulties getting this module installed. 21 | 22 | ## Documentation 23 | 24 | The cmdlets are yet not documented completely so Get-Help will not show help for all the cmdlets. This ReadTheDocs site is the first step to documenting the module. 25 | 26 | ## Tutorials 27 | 28 | There are a number of tutorials available on the web. The below two were written by the author of the NTFSSecurity module. 29 | 30 | [NTFSSecurity Tutorial 1 - Getting, adding and removing permissions](http://blogs.technet.com/b/fieldcoding/archive/2014/12/05/ntfssecurity-tutorial-1-getting-adding-and-removing-permissions.aspx) 31 | [NTFSSecurity Tutorial 2 - Managing NTFS Inheritance and Using Privileges](http://blogs.technet.com/b/fieldcoding/archive/2014/12/05/ntfssecurity-tutorial-2-managing-ntfs-inheritance-and-using-privileges.aspx) 32 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Raimund Andrée [MSFT] 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Log/Log.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {66624E57-402E-44F4-A072-9DB1827A5E20} 8 | Library 9 | Properties 10 | Log 11 | Log 12 | v4.5.2 13 | 512 14 | SAK 15 | SAK 16 | SAK 17 | SAK 18 | 19 | 20 | 21 | 22 | true 23 | full 24 | false 25 | bin\Debug\ 26 | DEBUG;TRACE 27 | prompt 28 | 4 29 | false 30 | 31 | 32 | pdbonly 33 | true 34 | bin\Release\ 35 | TRACE 36 | prompt 37 | 4 38 | false 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 62 | -------------------------------------------------------------------------------- /Log/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("Log")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("Log")] 13 | [assembly: AssemblyCopyright("Copyright © 2012")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("642209e6-51c3-4e00-936f-e0a41b3c65de")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /NTFSSecurity/AccessCmdlets/GetOrphanedAccess.cs: -------------------------------------------------------------------------------- 1 | using Alphaleonis.Win32.Filesystem; 2 | using Security2; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Management.Automation; 7 | 8 | namespace NTFSSecurity 9 | { 10 | [Cmdlet(VerbsCommon.Get, "NTFSOrphanedAccess")] 11 | [OutputType(typeof(FileSystemAccessRule2))] 12 | public class GetOrphanedAccess : GetAccess 13 | { 14 | int orphanedSidCount = 0; 15 | 16 | protected override void ProcessRecord() 17 | { 18 | IEnumerable acl = null; 19 | FileSystemInfo item = null; 20 | 21 | foreach (var path in paths) 22 | { 23 | try 24 | { 25 | item = this.GetFileSystemInfo2(path); 26 | } 27 | catch (Exception ex) 28 | { 29 | this.WriteError(new ErrorRecord(ex, "ReadFileError", ErrorCategory.OpenError, path)); 30 | continue; 31 | } 32 | 33 | try 34 | { 35 | acl = FileSystemAccessRule2.GetFileSystemAccessRules(item, !ExcludeExplicit, !ExcludeInherited, getInheritedFrom); 36 | } 37 | catch (UnauthorizedAccessException) 38 | { 39 | try 40 | { 41 | var ownerInfo = FileSystemOwner.GetOwner(item); 42 | var previousOwner = ownerInfo.Owner; 43 | 44 | FileSystemOwner.SetOwner(item, System.Security.Principal.WindowsIdentity.GetCurrent().User); 45 | 46 | acl = FileSystemAccessRule2.GetFileSystemAccessRules(item, !ExcludeExplicit, !ExcludeInherited, getInheritedFrom); 47 | 48 | FileSystemOwner.SetOwner(item, previousOwner); 49 | } 50 | catch (Exception ex2) 51 | { 52 | this.WriteError(new ErrorRecord(ex2, "AddAceError", ErrorCategory.WriteError, path)); 53 | } 54 | } 55 | catch (Exception ex) 56 | { 57 | this.WriteWarning(string.Format("Could not read item {0}. The error was: {1}", path, ex.Message)); 58 | } 59 | finally 60 | { 61 | if (acl != null) 62 | { 63 | var orphanedAces = acl.Where(ace => string.IsNullOrEmpty(ace.Account.AccountName)); 64 | orphanedSidCount += orphanedAces.Count(); 65 | 66 | WriteVerbose(string.Format("Item {0} knows about {1} orphaned SIDs in its ACL", path, orphanedAces.Count())); 67 | 68 | orphanedAces.ForEach(ace => WriteObject(ace)); 69 | } 70 | } 71 | } 72 | } 73 | 74 | protected override void EndProcessing() 75 | { 76 | WriteVerbose(string.Format("Total orphaned Access Control Enties: {0}", orphanedSidCount)); 77 | base.EndProcessing(); 78 | } 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /NTFSSecurity/AuditCmdlets/Get-OrphanedAudit.cs: -------------------------------------------------------------------------------- 1 | using Alphaleonis.Win32.Filesystem; 2 | using Security2; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Management.Automation; 7 | 8 | namespace NTFSSecurity.AuditCmdlets 9 | { 10 | [Cmdlet(VerbsCommon.Get, "NTFSOrphanedAudit")] 11 | [OutputType(typeof(FileSystemAuditRule2))] 12 | public class GetOrphanedAudit : GetAudit 13 | { 14 | int orphanedSidCount = 0; 15 | 16 | protected override void ProcessRecord() 17 | { 18 | IEnumerable acl; 19 | FileSystemInfo item = null; 20 | 21 | foreach (var p in paths) 22 | { 23 | try 24 | { 25 | item = this.GetFileSystemInfo2(p); 26 | } 27 | catch (Exception ex) 28 | { 29 | this.WriteError(new ErrorRecord(ex, "ReadError", ErrorCategory.OpenError, p)); 30 | continue; 31 | } 32 | 33 | try 34 | { 35 | acl = FileSystemAuditRule2.GetFileSystemAuditRules(item, !ExcludeExplicit, !ExcludeInherited, getInheritedFrom); 36 | 37 | var orphanedAces = acl.Where(ace => string.IsNullOrEmpty(ace.Account.AccountName)); 38 | orphanedSidCount += orphanedAces.Count(); 39 | 40 | this.WriteVerbose(string.Format("Item {0} knows about {1} orphaned SIDs in its ACL", p, orphanedAces.Count())); 41 | this.WriteObject(orphanedAces); 42 | } 43 | catch (Exception ex) 44 | { 45 | this.WriteWarning(string.Format("Could not read item {0}. The error was: {1}", p, ex.Message)); 46 | } 47 | } 48 | } 49 | 50 | protected override void EndProcessing() 51 | { 52 | WriteVerbose(string.Format("Total orphaned Access Control Enties: {0}", orphanedSidCount)); 53 | base.EndProcessing(); 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /NTFSSecurity/CodeMembers.cs: -------------------------------------------------------------------------------- 1 | using Alphaleonis.Win32.Filesystem; 2 | using System.Management.Automation; 3 | 4 | namespace NTFSSecurity 5 | { 6 | public class FileSystemCodeMembers 7 | { 8 | public static string Mode(PSObject obj) 9 | { 10 | if (obj == null) 11 | { 12 | return string.Empty; 13 | } 14 | FileSystemInfo item = (FileSystemInfo)obj.BaseObject; 15 | if (item == null) 16 | { 17 | return string.Empty; 18 | } 19 | 20 | string text = ""; 21 | if ((item.Attributes & System.IO.FileAttributes.Directory) == System.IO.FileAttributes.Directory) 22 | { 23 | text += "d"; 24 | } 25 | else 26 | { 27 | text += "-"; 28 | } 29 | if ((item.Attributes & System.IO.FileAttributes.Archive) == System.IO.FileAttributes.Archive) 30 | { 31 | text += "a"; 32 | } 33 | else 34 | { 35 | text += "-"; 36 | } 37 | if ((item.Attributes & System.IO.FileAttributes.ReadOnly) == System.IO.FileAttributes.ReadOnly) 38 | { 39 | text += "r"; 40 | } 41 | else 42 | { 43 | text += "-"; 44 | } 45 | if ((item.Attributes & System.IO.FileAttributes.Hidden) == System.IO.FileAttributes.Hidden) 46 | { 47 | text += "h"; 48 | } 49 | else 50 | { 51 | text += "-"; 52 | } 53 | if ((item.Attributes & System.IO.FileAttributes.System) == System.IO.FileAttributes.System) 54 | { 55 | text += "s"; 56 | } 57 | else 58 | { 59 | text += "-"; 60 | } 61 | return text; 62 | } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /NTFSSecurity/Extensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Alphaleonis.Win32.Filesystem; 4 | 5 | namespace NTFSSecurity 6 | { 7 | public static class Extensions 8 | { 9 | public static void ForEach(this IEnumerable source, Action action) 10 | { 11 | if (source == null) { throw new ArgumentException(); } 12 | if (action == null) { throw new ArgumentException(); } 13 | 14 | foreach (T element in source) 15 | { 16 | action(element); 17 | } 18 | } 19 | 20 | public static FileSystemInfo GetParent(this FileSystemInfo item) 21 | { 22 | var parentPath = System.IO.Path.GetDirectoryName(item.FullName); 23 | 24 | if (File.Exists(parentPath)) 25 | { 26 | return new FileInfo(parentPath); 27 | } 28 | else if (Directory.Exists(parentPath)) 29 | { 30 | return new DirectoryInfo(parentPath); 31 | } 32 | else 33 | { 34 | throw new System.IO.FileNotFoundException(); 35 | } 36 | } 37 | 38 | public static System.IO.FileSystemInfo GetParent(this System.IO.FileSystemInfo item) 39 | { 40 | var parentPath = System.IO.Path.GetDirectoryName(item.FullName); 41 | 42 | if (File.Exists(parentPath)) 43 | { 44 | return new System.IO.FileInfo(parentPath); 45 | } 46 | else if (Directory.Exists(parentPath)) 47 | { 48 | return new System.IO.DirectoryInfo(parentPath); 49 | } 50 | else 51 | { 52 | throw new System.IO.FileNotFoundException(); 53 | } 54 | } 55 | } 56 | } -------------------------------------------------------------------------------- /NTFSSecurity/ItemCmdlets/GetDiskSpace.cs: -------------------------------------------------------------------------------- 1 | using Alphaleonis.Win32.Filesystem; 2 | using System.Linq; 3 | using System.Management.Automation; 4 | 5 | namespace NTFSSecurity 6 | { 7 | [Cmdlet(VerbsCommon.Get, "DiskSpace")] 8 | [OutputType(typeof(DiskSpaceInfo))] 9 | public class GetDiskSpace : PSCmdlet 10 | { 11 | private string[] driveLetter; 12 | 13 | [Parameter(Position = 1)] 14 | [ValidatePattern("^[A-Za-z]:$")] 15 | public string[] DriveLetter 16 | { 17 | get { return driveLetter; } 18 | set { driveLetter = value; } 19 | } 20 | 21 | protected override void BeginProcessing() 22 | { 23 | base.BeginProcessing(); 24 | } 25 | 26 | protected override void ProcessRecord() 27 | { 28 | var volumes = Alphaleonis.Win32.Filesystem.Volume.EnumerateVolumes(); 29 | 30 | if (driveLetter == null) 31 | { 32 | driveLetter = volumes.ToArray(); 33 | } 34 | 35 | foreach (var letter in driveLetter) 36 | { 37 | var diskSpaceInfo = new DiskSpaceInfo(letter); 38 | try 39 | { 40 | diskSpaceInfo.Refresh(); 41 | if (diskSpaceInfo.TotalNumberOfBytes > 0) 42 | { 43 | this.WriteObject(diskSpaceInfo); 44 | } 45 | } 46 | catch 47 | { 48 | this.WriteWarning(string.Format("Could not get drive details for '{0}'", letter)); 49 | } 50 | } 51 | } 52 | 53 | protected override void EndProcessing() 54 | { 55 | base.EndProcessing(); 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /NTFSSecurity/ItemCmdlets/GetItem2.cs: -------------------------------------------------------------------------------- 1 | using Alphaleonis.Win32.Filesystem; 2 | using System.Collections.Generic; 3 | using System.Management.Automation; 4 | 5 | namespace NTFSSecurity 6 | { 7 | [Cmdlet(VerbsCommon.Get, "Item2")] 8 | [OutputType(typeof(FileInfo), typeof(DirectoryInfo))] 9 | public class GetItem2 : BaseCmdlet 10 | { 11 | System.Reflection.MethodInfo modeMethodInfo = null; 12 | 13 | [Parameter(Position = 1, ValueFromPipeline = true, ValueFromPipelineByPropertyName = true)] 14 | [ValidateNotNullOrEmpty] 15 | [Alias("FullName")] 16 | public string[] Path 17 | { 18 | get { return paths.ToArray(); } 19 | set 20 | { 21 | paths.Clear(); 22 | paths.AddRange(value); 23 | } 24 | } 25 | 26 | protected override void BeginProcessing() 27 | { 28 | base.BeginProcessing(); 29 | 30 | if (paths.Count == 0) 31 | { 32 | paths = new List() { GetVariableValue("PWD").ToString() }; 33 | } 34 | 35 | modeMethodInfo = typeof(FileSystemCodeMembers).GetMethod("Mode"); 36 | } 37 | 38 | protected override void ProcessRecord() 39 | { 40 | foreach (var path in paths) 41 | { 42 | try 43 | { 44 | var item = new PSObject(GetFileSystemInfo2(path)); 45 | item.Properties.Add(new PSCodeProperty("Mode", modeMethodInfo)); 46 | 47 | WriteObject(item); 48 | } 49 | catch (System.IO.FileNotFoundException ex) 50 | { 51 | WriteError(new ErrorRecord(ex, "FileNotFound", ErrorCategory.ObjectNotFound, path)); 52 | } 53 | } 54 | } 55 | 56 | protected override void EndProcessing() 57 | { 58 | base.EndProcessing(); 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /NTFSSecurity/ItemCmdlets/RemoveItem2.cs: -------------------------------------------------------------------------------- 1 | using Alphaleonis.Win32.Filesystem; 2 | using System; 3 | using System.Management.Automation; 4 | 5 | namespace NTFSSecurity 6 | { 7 | [Cmdlet(VerbsCommon.Remove, "Item2", SupportsShouldProcess = true)] 8 | public class RemoveItem2 : BaseCmdlet 9 | { 10 | private SwitchParameter force; 11 | private SwitchParameter recurse; 12 | private string filter; 13 | private bool passThru; 14 | 15 | [Parameter(Position = 1, ValueFromPipeline = true, ValueFromPipelineByPropertyName = true)] 16 | [ValidateNotNullOrEmpty] 17 | [Alias("FullName")] 18 | public string[] Path 19 | { 20 | get { return paths.ToArray(); } 21 | set 22 | { 23 | paths.Clear(); 24 | paths.AddRange(value); 25 | } 26 | } 27 | 28 | [Parameter] 29 | public SwitchParameter Force 30 | { 31 | get { return force; } 32 | set { force = value; } 33 | } 34 | 35 | [Parameter] 36 | public SwitchParameter Recurse 37 | { 38 | get { return recurse; } 39 | set { recurse = value; } 40 | } 41 | 42 | [Parameter] 43 | public SwitchParameter PassThru 44 | { 45 | get { return passThru; } 46 | set { passThru = value; } 47 | } 48 | 49 | protected override void BeginProcessing() 50 | { 51 | base.BeginProcessing(); 52 | } 53 | 54 | protected override void ProcessRecord() 55 | { 56 | foreach (var path in paths) 57 | { 58 | FileSystemInfo item = null; 59 | 60 | try 61 | { 62 | item = GetFileSystemInfo2(path); 63 | } 64 | catch (System.IO.FileNotFoundException ex) 65 | { 66 | WriteError(new ErrorRecord(ex, "FileNotFound", ErrorCategory.ObjectNotFound, path)); 67 | return; 68 | } 69 | 70 | try 71 | { 72 | if (item is FileInfo) 73 | { 74 | if (ShouldProcess(item.ToString(), "Remove File")) 75 | { 76 | ((FileInfo)item).Delete(force); 77 | WriteVerbose(string.Format("File '{0}' was removed", item.ToString())); 78 | } 79 | } 80 | else 81 | { 82 | if (ShouldProcess(item.ToString(), "Remove Directory")) 83 | { 84 | ((DirectoryInfo)item).Delete(recurse, force); 85 | WriteVerbose(string.Format("Directory '{0}' was removed", item.ToString())); 86 | } 87 | } 88 | 89 | if (passThru) 90 | WriteObject(item); 91 | } 92 | catch (System.IO.IOException ex) 93 | { 94 | WriteError(new ErrorRecord(ex, "DeleteError", ErrorCategory.InvalidData, path)); 95 | } 96 | catch (Exception ex) 97 | { 98 | WriteError(new ErrorRecord(ex, "DeleteError", ErrorCategory.NotSpecified, path)); 99 | } 100 | } 101 | } 102 | 103 | protected override void EndProcessing() 104 | { 105 | base.EndProcessing(); 106 | } 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /NTFSSecurity/LinkCmdlets/GetHardLink.cs: -------------------------------------------------------------------------------- 1 | using Alphaleonis.Win32.Filesystem; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Management.Automation; 5 | 6 | namespace NTFSSecurity 7 | { 8 | [Cmdlet(VerbsCommon.Get, "NTFSHardLink")] 9 | [OutputType(typeof(FileInfo), typeof(DirectoryInfo))] 10 | public class GetHardLink : BaseCmdlet 11 | { 12 | System.Reflection.MethodInfo modeMethodInfo = null; 13 | 14 | [Parameter(Position = 1, ValueFromPipeline = true, ValueFromPipelineByPropertyName = true)] 15 | [ValidateNotNullOrEmpty] 16 | [Alias("FullName")] 17 | public string[] Path 18 | { 19 | get { return paths.ToArray(); } 20 | set 21 | { 22 | paths.Clear(); 23 | paths.AddRange(value); 24 | } 25 | } 26 | 27 | protected override void BeginProcessing() 28 | { 29 | base.BeginProcessing(); 30 | 31 | if (paths.Count == 0) 32 | { 33 | paths = new List() { GetVariableValue("PWD").ToString() }; 34 | } 35 | 36 | modeMethodInfo = typeof(FileSystemCodeMembers).GetMethod("Mode"); 37 | } 38 | 39 | protected override void ProcessRecord() 40 | { 41 | foreach (var path in paths) 42 | { 43 | try 44 | { 45 | var root = System.IO.Path.GetPathRoot(GetRelativePath(path)); 46 | 47 | //access the path to make sure it exists and is a file 48 | var item = GetFileSystemInfo2(path); 49 | 50 | if (item is DirectoryInfo) 51 | throw new ArgumentException("The item must be a file"); 52 | 53 | var links = File.EnumerateHardlinks(item.FullName); 54 | 55 | foreach (var link in links) 56 | { 57 | var target = new PSObject(GetFileSystemInfo2(System.IO.Path.Combine(root, link.Substring(1)))); 58 | target.Properties.Add(new PSCodeProperty("Mode", modeMethodInfo)); 59 | WriteObject(target); 60 | } 61 | } 62 | catch (System.IO.FileNotFoundException ex) 63 | { 64 | WriteError(new ErrorRecord(ex, "FileNotFound", ErrorCategory.ObjectNotFound, path)); 65 | } 66 | } 67 | } 68 | 69 | protected override void EndProcessing() 70 | { 71 | base.EndProcessing(); 72 | } 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /NTFSSecurity/LinkCmdlets/NewHardLink.cs: -------------------------------------------------------------------------------- 1 | using Alphaleonis.Win32.Filesystem; 2 | using System; 3 | using System.Management.Automation; 4 | 5 | namespace NTFSSecurity 6 | { 7 | [Cmdlet(VerbsCommon.New, "NTFSHardLink")] 8 | [OutputType(typeof(FileInfo), typeof(DirectoryInfo))] 9 | public class NewHardLink : BaseCmdlet 10 | { 11 | string target; 12 | private bool passThru; 13 | System.Reflection.MethodInfo modeMethodInfo = null; 14 | 15 | [Parameter(Position = 1, ValueFromPipeline = true, ValueFromPipelineByPropertyName = true)] 16 | [ValidateNotNullOrEmpty] 17 | [Alias("FullName")] 18 | public string Path 19 | { 20 | get { return paths[0]; } 21 | set 22 | { 23 | paths.Clear(); 24 | paths.Add(value); 25 | } 26 | } 27 | 28 | [Parameter(Position = 2, ValueFromPipeline = true, ValueFromPipelineByPropertyName = true)] 29 | [ValidateNotNullOrEmpty] 30 | public string Target 31 | { 32 | get { return target; } 33 | set { target = value; } 34 | } 35 | 36 | [Parameter] 37 | public SwitchParameter PassThru 38 | { 39 | get { return passThru; } 40 | set { passThru = value; } 41 | } 42 | 43 | protected override void BeginProcessing() 44 | { 45 | base.BeginProcessing(); 46 | 47 | modeMethodInfo = typeof(FileSystemCodeMembers).GetMethod("Mode"); 48 | } 49 | 50 | protected override void ProcessRecord() 51 | { 52 | var path = paths[0]; 53 | 54 | path = GetRelativePath(path); 55 | target = GetRelativePath(target); 56 | var root = System.IO.Path.GetPathRoot(path); 57 | 58 | try 59 | { 60 | FileSystemInfo temp = null; 61 | 62 | if (TryGetFileSystemInfo2(path, out temp)) 63 | throw new ArgumentException(string.Format("The file '{0}' does already exist, cannot create the link", path)); 64 | 65 | if (!TryGetFileSystemInfo2(target, out temp)) 66 | throw new ArgumentException("The target path exist, cannot create the link"); 67 | else 68 | if (temp is DirectoryInfo) 69 | throw new ArgumentException("The target is not a file, cannot create the link"); 70 | 71 | File.CreateHardlink(path, target); 72 | 73 | if (passThru) 74 | { 75 | var links = File.EnumerateHardlinks(path); 76 | 77 | foreach (var link in links) 78 | { 79 | var target = new PSObject(GetFileSystemInfo2(System.IO.Path.Combine(root, link.Substring(1)))); 80 | target.Properties.Add(new PSCodeProperty("Mode", modeMethodInfo)); 81 | WriteObject(target); 82 | } 83 | } 84 | } 85 | catch (System.IO.FileNotFoundException ex) 86 | { 87 | WriteError(new ErrorRecord(ex, "CreateHardLinkError", ErrorCategory.WriteError, path)); 88 | } 89 | } 90 | 91 | protected override void EndProcessing() 92 | { 93 | base.EndProcessing(); 94 | } 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /NTFSSecurity/LinkCmdlets/NewSymbolicLink.cs: -------------------------------------------------------------------------------- 1 | using Alphaleonis.Win32.Filesystem; 2 | using System; 3 | using System.Management.Automation; 4 | 5 | namespace NTFSSecurity 6 | { 7 | [Cmdlet(VerbsCommon.New, "NTFSSymbolicLink")] 8 | [OutputType(typeof(FileInfo), typeof(DirectoryInfo))] 9 | public class NewSymbolicLink : BaseCmdlet 10 | { 11 | string target; 12 | private bool passThru; 13 | System.Reflection.MethodInfo modeMethodInfo = null; 14 | 15 | [Parameter(Position = 1, ValueFromPipeline = true, ValueFromPipelineByPropertyName = true)] 16 | [ValidateNotNullOrEmpty] 17 | [Alias("FullName")] 18 | public string Path 19 | { 20 | get { return paths[0]; } 21 | set 22 | { 23 | paths.Clear(); 24 | paths.Add(value); 25 | } 26 | } 27 | 28 | [Parameter(Position = 2, ValueFromPipeline = true, ValueFromPipelineByPropertyName = true)] 29 | [ValidateNotNullOrEmpty] 30 | public string Target 31 | { 32 | get { return target; } 33 | set { target = value; } 34 | } 35 | 36 | [Parameter] 37 | public SwitchParameter PassThru 38 | { 39 | get { return passThru; } 40 | set { passThru = value; } 41 | } 42 | 43 | protected override void BeginProcessing() 44 | { 45 | base.BeginProcessing(); 46 | 47 | modeMethodInfo = typeof(FileSystemCodeMembers).GetMethod("Mode"); 48 | } 49 | 50 | protected override void ProcessRecord() 51 | { 52 | var path = paths[0]; 53 | 54 | path = GetRelativePath(path); 55 | target = GetRelativePath(target); 56 | FileSystemInfo targetItem = null; 57 | var root = System.IO.Path.GetPathRoot(path); 58 | 59 | try 60 | { 61 | targetItem = GetFileSystemInfo2(target); 62 | 63 | FileSystemInfo temp; 64 | if (TryGetFileSystemInfo2(path, out temp)) 65 | { 66 | throw new ArgumentException("The path does already exist, cannot create link"); 67 | } 68 | 69 | File.CreateSymbolicLink(path, target, targetItem is FileInfo ? SymbolicLinkTarget.File : SymbolicLinkTarget.Directory); 70 | 71 | if (passThru) 72 | { 73 | WriteObject(new FileInfo(path)); 74 | } 75 | } 76 | catch (System.IO.FileNotFoundException ex) 77 | { 78 | WriteError(new ErrorRecord(ex, "CreateSymbolicLinkError", ErrorCategory.ObjectNotFound, path)); 79 | } 80 | } 81 | 82 | protected override void EndProcessing() 83 | { 84 | base.EndProcessing(); 85 | } 86 | } 87 | } -------------------------------------------------------------------------------- /NTFSSecurity/MiscCmdlets/GetFileHash2.cs: -------------------------------------------------------------------------------- 1 | using Alphaleonis.Win32.Filesystem; 2 | using Security2; 3 | using System; 4 | using System.Management.Automation; 5 | using Security2.FileSystem.FileInfo; 6 | 7 | namespace NTFSSecurity 8 | { 9 | [Cmdlet(VerbsCommon.Get, "FileHash2")] 10 | [OutputType(typeof(FileSystemAccessRule2))] 11 | public class GetFileHash2 : BaseCmdlet 12 | { 13 | private HashAlgorithms algorithm = HashAlgorithms.SHA256; 14 | 15 | [Parameter(Mandatory = true, Position = 1, ValueFromPipeline = true, ValueFromPipelineByPropertyName = true)] 16 | [ValidateNotNullOrEmpty] 17 | [Alias("FullName")] 18 | public string[] Path 19 | { 20 | get { return paths.ToArray(); } 21 | set 22 | { 23 | paths.Clear(); 24 | paths.AddRange(value); 25 | } 26 | } 27 | 28 | [Parameter(Position = 2, ValueFromPipelineByPropertyName = true)] 29 | public HashAlgorithms Algorithm 30 | { 31 | get { return algorithm; } 32 | set { algorithm = value; } 33 | } 34 | 35 | protected override void BeginProcessing() 36 | { 37 | base.BeginProcessing(); 38 | } 39 | 40 | protected override void ProcessRecord() 41 | { 42 | string hash = string.Empty; 43 | FileSystemInfo item = null; 44 | 45 | foreach (var path in paths) 46 | { 47 | try 48 | { 49 | item = GetFileSystemInfo2(path) as FileInfo; 50 | if (item == null) 51 | return; 52 | } 53 | catch (Exception ex) 54 | { 55 | WriteError(new ErrorRecord(ex, "ReadFileError", ErrorCategory.OpenError, path)); 56 | continue; 57 | } 58 | 59 | try 60 | { 61 | hash = ((FileInfo)item).GetHash(algorithm); 62 | } 63 | catch (UnauthorizedAccessException) 64 | { 65 | try 66 | { 67 | var ownerInfo = FileSystemOwner.GetOwner(item); 68 | var previousOwner = ownerInfo.Owner; 69 | 70 | FileSystemOwner.SetOwner(item, System.Security.Principal.WindowsIdentity.GetCurrent().User); 71 | 72 | hash = ((FileInfo)item).GetHash(algorithm); 73 | 74 | FileSystemOwner.SetOwner(item, previousOwner); 75 | } 76 | catch (Exception ex2) 77 | { 78 | WriteError(new ErrorRecord(ex2, "GetHashError", ErrorCategory.WriteError, path)); 79 | } 80 | } 81 | catch (Exception ex) 82 | { 83 | WriteError(new ErrorRecord(ex, "GetHashError", ErrorCategory.WriteError, path)); 84 | } 85 | 86 | var result = new PSObject(item); 87 | result.Properties.Add(new PSNoteProperty("Hash", hash)); 88 | result.Properties.Add(new PSNoteProperty("Algorithm", algorithm.ToString())); 89 | result.TypeNames.Insert(0, "Alphaleonis.Win32.Filesystem.FileInfo+Hash"); 90 | WriteObject(result); 91 | } 92 | } 93 | 94 | protected override void EndProcessing() 95 | { 96 | base.EndProcessing(); 97 | } 98 | } 99 | } -------------------------------------------------------------------------------- /NTFSSecurity/NTFSSecurity.Init.ps1: -------------------------------------------------------------------------------- 1 | #region Internals 2 | #region C# Code 3 | $type_NTFS1 = @' 4 | using System; 5 | using System.IO; 6 | using System.Collections; 7 | using System.Runtime.InteropServices; 8 | using Microsoft.Win32.SafeHandles; 9 | 10 | namespace NTFS 11 | { 12 | public class DriveInfoExt 13 | { 14 | [DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Auto)] 15 | static extern bool GetDiskFreeSpace(string lpRootPathName, 16 | out uint lpSectorsPerCluster, 17 | out uint lpBytesPerSector, 18 | out uint lpNumberOfFreeClusters, 19 | out uint lpTotalNumberOfClusters); 20 | 21 | DriveInfo _drive = null; 22 | uint _sectorsPerCluster = 0; 23 | uint _bytesPerSector = 0; 24 | uint _numberOfFreeClusters = 0; 25 | uint _totalNumberOfClusters = 0; 26 | 27 | public uint SectorsPerCluster { get { return _sectorsPerCluster; } } 28 | public uint BytesPerSector { get { return _bytesPerSector; } } 29 | public uint NumberOfFreeClusters { get { return _numberOfFreeClusters; } } 30 | public uint TotalNumberOfClusters { get { return _totalNumberOfClusters; } } 31 | public DriveInfo Drive { get { return _drive; } } 32 | public string DriveName { get { return _drive.Name; } } 33 | public string VolumeName { get { return _drive.VolumeLabel; } } 34 | 35 | public DriveInfoExt(string DriveName) 36 | { 37 | _drive = new DriveInfo(DriveName); 38 | 39 | GetDiskFreeSpace(_drive.Name, 40 | out _sectorsPerCluster, 41 | out _bytesPerSector, 42 | out _numberOfFreeClusters, 43 | out _totalNumberOfClusters); 44 | } 45 | } 46 | 47 | public class FileInfoExt 48 | { 49 | [DllImport("kernel32.dll", SetLastError = true, EntryPoint = "GetCompressedFileSize")] 50 | static extern uint GetCompressedFileSize(string lpFileName, out uint lpFileSizeHigh); 51 | 52 | public static ulong GetCompressedFileSize(string filename) 53 | { 54 | uint high; 55 | uint low; 56 | low = GetCompressedFileSize(filename, out high); 57 | int error = Marshal.GetLastWin32Error(); 58 | 59 | if (high == 0 && low == 0xFFFFFFFF && error != 0) 60 | { 61 | throw new System.ComponentModel.Win32Exception(error); 62 | } 63 | else 64 | { 65 | return ((ulong)high << 32) + low; 66 | } 67 | } 68 | } 69 | } 70 | '@ 71 | #endregion 72 | #endregion 73 | 74 | Add-Type -TypeDefinition $type_NTFS1 75 | Add-Type -Path $PSScriptRoot\Security2.dll 76 | Add-Type -Path $PSScriptRoot\PrivilegeControl.dll -ReferencedAssemblies $PSScriptRoot\ProcessPrivileges.dll 77 | Add-Type -Path $PSScriptRoot\ProcessPrivileges.dll 78 | 79 | #using Update-FormatData and not FormatsToProcess in the PSD1 as FormatsToProcess does not offer 80 | #putting format data in front of the default data. This is required to make the new formatter the default ones. 81 | Update-FormatData -PrependPath $PSScriptRoot\NTFSSecurity.format.ps1xml -------------------------------------------------------------------------------- /NTFSSecurity/NTFSSecurity.psd1: -------------------------------------------------------------------------------- 1 | @{ 2 | ModuleToProcess = 'NTFSSecurity.psm1' 3 | 4 | ModuleVersion = '4.2.5' 5 | 6 | GUID = 'cd303a6c-f405-4dcb-b1ce-fbc2c52264e9' 7 | 8 | Author = 'Raimund Andree' 9 | 10 | CompanyName = 'Raimund Andree' 11 | 12 | Copyright = '2018' 13 | 14 | Description = 'Windows PowerShell Module for managing file and folder security on NTFS volumes' 15 | 16 | PowerShellVersion = '2.0' 17 | 18 | CompatiblePSEditions = 'Core', 'Desktop' 19 | 20 | DotNetFrameworkVersion = '3.5' 21 | 22 | ScriptsToProcess = @('NTFSSecurity.Init.ps1') 23 | 24 | TypesToProcess = @('NTFSSecurity.types.ps1xml') 25 | 26 | FormatsToProcess = @() 27 | 28 | NestedModules = @('NTFSSecurity.dll') 29 | 30 | AliasesToExport = '*' 31 | 32 | CmdletsToExport = 'Add-NTFSAccess', 33 | 'Clear-NTFSAccess', 34 | 'Disable-NTFSAccessInheritance', 35 | 'Enable-NTFSAccessInheritance', 36 | 'Get-NTFSAccess', 37 | 'Get-NTFSEffectiveAccess', 38 | 'Get-NTFSOrphanedAccess', 39 | 'Get-NTFSSimpleAccess', 40 | 'Remove-NTFSAccess', 41 | 'Show-NTFSSimpleAccess', 42 | #---------------------------------------------- 43 | 'Add-NTFSAudit', 44 | 'Clear-NTFSAudit', 45 | 'Disable-NTFSAuditInheritance', 46 | 'Enable-NTFSAuditInheritance', 47 | 'Get-NTFSAudit', 48 | 'Get-NTFSOrphanedAudit', 49 | 'Remove-NTFSAudit', 50 | #---------------------------------------------- 51 | 'Disable-NTFSAccessInheritance', 52 | 'Disable-NTFSAuditInheritance', 53 | 'Enable-NTFSAccessInheritance', 54 | 'Enable-NTFSAuditInheritance', 55 | 'Get-NTFSInheritance', 56 | 'Set-NTFSInheritance', 57 | #---------------------------------------------- 58 | 'Get-NTFSOwner', 59 | 'Set-NTFSOwner', 60 | #---------------------------------------------- 61 | 'Get-NTFSSecurityDescriptor', 62 | 'Set-NTFSSecurityDescriptor', 63 | #---------------------------------------------- 64 | 'Disable-Privileges', 65 | 'Enable-Privileges', 66 | 'Get-Privileges', 67 | #---------------------------------------------- 68 | 'Copy-Item2', 69 | 'Get-ChildItem2', 70 | 'Get-Item2', 71 | 'Move-Item2', 72 | 'Remove-Item2', 73 | #---------------------------------------------- 74 | 'Test-Path2', 75 | #---------------------------------------------- 76 | 'Get-NTFSHardLink', 77 | 'New-NTFSHardLink', 78 | 'New-NTFSSymbolicLink', 79 | #---------------------------------------------- 80 | 'Get-DiskSpace', 81 | 'Get-FileHash2' 82 | 83 | FileList = @('NTFSSecurity.dll', 'NTFSSecurity.types.ps1xml', 'NTFSSecurity.format.ps1xml', 'NTFSSecurity.Init.ps1', 'NTFSSecurity.psm1') 84 | 85 | PrivateData = @{ 86 | EnablePrivileges = $true 87 | GetInheritedFrom = $true 88 | GetFileSystemModeProperty = $true 89 | ShowAccountSid = $false 90 | IdentifyHardLinks = $true 91 | 92 | PSData = @{ 93 | Tags = @('AccessControl', 'ACL', 'DirectorySecurity', 'FileSecurity', 'FileSystem', 'FileSystemSecurity', 'NTFS', 'Module', 'AccessRights') 94 | LicenseUri = 'https://github.com/raandree/NTFSSecurity/blob/master/LICENSE' 95 | ProjectUri = 'https://github.com/raandree/NTFSSecurity' 96 | } 97 | } 98 | } -------------------------------------------------------------------------------- /NTFSSecurity/NTFSSecurity.psm1: -------------------------------------------------------------------------------- 1 | New-Alias -Name dir2 -Value Get-ChildItem2 -ErrorAction SilentlyContinue 2 | New-Alias -Name gi2 -Value Get-Item2 -ErrorAction SilentlyContinue 3 | New-Alias -Name rm2 -Value Remove-Item2 -ErrorAction SilentlyContinue 4 | New-Alias -Name del2 -Value Remove-Item2 -ErrorAction SilentlyContinue 5 | 6 | Export-ModuleMember -Alias * -Function * -Cmdlet * -------------------------------------------------------------------------------- /NTFSSecurity/PathCmdlets/TestPath2.cs: -------------------------------------------------------------------------------- 1 | using Alphaleonis.Win32.Filesystem; 2 | using System.Collections.Generic; 3 | using System.Management.Automation; 4 | 5 | namespace NTFSSecurity 6 | { 7 | [Cmdlet(VerbsDiagnostic.Test, "Path2")] 8 | [OutputType(typeof(FileInfo), typeof(DirectoryInfo))] 9 | public class TestPath2 : BaseCmdlet 10 | { 11 | private TestPathType pathType = TestPathType.Any; 12 | 13 | [Parameter(Position = 1, Mandatory = true, ValueFromPipeline = true, ValueFromPipelineByPropertyName = true)] 14 | [ValidateNotNullOrEmpty] 15 | [Alias("FullName")] 16 | public string[] Path 17 | { 18 | get { return paths.ToArray(); } 19 | set 20 | { 21 | paths.Clear(); 22 | paths.AddRange(value); 23 | } 24 | } 25 | 26 | [Parameter(ValueFromPipelineByPropertyName = true)] 27 | public TestPathType PathType 28 | { 29 | get { return pathType; } 30 | set { pathType = value; } 31 | } 32 | 33 | protected override void BeginProcessing() 34 | { 35 | base.BeginProcessing(); 36 | 37 | if (paths.Count == 0) 38 | { 39 | paths = new List() { GetVariableValue("PWD").ToString() }; 40 | } 41 | } 42 | 43 | protected override void ProcessRecord() 44 | { 45 | foreach (var path in paths) 46 | { 47 | try 48 | { 49 | FileSystemInfo item; 50 | TryGetFileSystemInfo2(path, out item); 51 | 52 | if (item == null) 53 | WriteObject(false); 54 | else 55 | { 56 | if (PathType == TestPathType.Any) 57 | WriteObject(true); 58 | else if (PathType == TestPathType.Container & item is DirectoryInfo) 59 | WriteObject(true); 60 | else if (PathType == TestPathType.Leaf & item is FileInfo) 61 | WriteObject(true); 62 | else 63 | WriteObject(false); 64 | } 65 | } 66 | catch (System.IO.FileNotFoundException ex) 67 | { 68 | WriteError(new ErrorRecord(ex, "PathNotFound", ErrorCategory.ObjectNotFound, path)); 69 | } 70 | } 71 | } 72 | 73 | protected override void EndProcessing() 74 | { 75 | base.EndProcessing(); 76 | } 77 | } 78 | 79 | public enum TestPathType 80 | { 81 | Any, 82 | Container, 83 | Leaf 84 | } 85 | } -------------------------------------------------------------------------------- /NTFSSecurity/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("NTFSSecurity")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("Microsoft")] 12 | [assembly: AssemblyProduct("NTFSSecurity")] 13 | [assembly: AssemblyCopyright("Copyright © Microsoft 2012")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("8f2c77c5-b143-4194-9e6f-840dfe19e5c4")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("4.2.1.0")] 36 | [assembly: AssemblyFileVersion("4.2.1.0")] 37 | -------------------------------------------------------------------------------- /NTFSSecurity/Properties/Resources.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.42000 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace NTFSSecurity.Properties { 12 | using System; 13 | 14 | 15 | /// 16 | /// A strongly-typed resource class, for looking up localized strings, etc. 17 | /// 18 | // This class was auto-generated by the StronglyTypedResourceBuilder 19 | // class via a tool like ResGen or Visual Studio. 20 | // To add or remove a member, edit your .ResX file then rerun ResGen 21 | // with the /str option, or rebuild your VS project. 22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "15.0.0.0")] 23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 25 | public class Resources { 26 | 27 | private static global::System.Resources.ResourceManager resourceMan; 28 | 29 | private static global::System.Globalization.CultureInfo resourceCulture; 30 | 31 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] 32 | internal Resources() { 33 | } 34 | 35 | /// 36 | /// Returns the cached ResourceManager instance used by this class. 37 | /// 38 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 39 | public static global::System.Resources.ResourceManager ResourceManager { 40 | get { 41 | if (object.ReferenceEquals(resourceMan, null)) { 42 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("NTFSSecurity.Properties.Resources", typeof(Resources).Assembly); 43 | resourceMan = temp; 44 | } 45 | return resourceMan; 46 | } 47 | } 48 | 49 | /// 50 | /// Overrides the current thread's CurrentUICulture property for all 51 | /// resource lookups using this strongly typed resource class. 52 | /// 53 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 54 | public static global::System.Globalization.CultureInfo Culture { 55 | get { 56 | return resourceCulture; 57 | } 58 | set { 59 | resourceCulture = value; 60 | } 61 | } 62 | 63 | /// 64 | /// Looks up a localized string similar to . 65 | /// 66 | public static string ContainerIcon { 67 | get { 68 | return ResourceManager.GetString("ContainerIcon", resourceCulture); 69 | } 70 | } 71 | 72 | /// 73 | /// Looks up a localized resource of type System.Drawing.Bitmap. 74 | /// 75 | public static System.Drawing.Bitmap IconContainer { 76 | get { 77 | object obj = ResourceManager.GetObject("IconContainer", resourceCulture); 78 | return ((System.Drawing.Bitmap)(obj)); 79 | } 80 | } 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /NTFSSecurity/Resources/IconContainer.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/raandree/NTFSSecurity/7a8a1a5347ef3336985b6c94f9193e11ef56b9af/NTFSSecurity/Resources/IconContainer.bmp -------------------------------------------------------------------------------- /NTFSSecurity/Resources/User.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/raandree/NTFSSecurity/7a8a1a5347ef3336985b6c94f9193e11ef56b9af/NTFSSecurity/Resources/User.jpg -------------------------------------------------------------------------------- /NTFSSecurity/Resources/container.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/raandree/NTFSSecurity/7a8a1a5347ef3336985b6c94f9193e11ef56b9af/NTFSSecurity/Resources/container.jpg -------------------------------------------------------------------------------- /NTFSSecurity/SecurityDescriptorCmdlets/GetSecurityDescriptor.cs: -------------------------------------------------------------------------------- 1 | using Alphaleonis.Win32.Filesystem; 2 | using Security2; 3 | using System; 4 | using System.Management.Automation; 5 | 6 | namespace NTFSSecurity 7 | { 8 | [Cmdlet(VerbsCommon.Get, "NTFSSecurityDescriptor")] 9 | [OutputType(typeof(FileSystemSecurity2))] 10 | public class GetSecurityDescriptor : BaseCmdletWithPrivControl 11 | { 12 | [Parameter(Position = 1, ValueFromPipeline = true, ValueFromPipelineByPropertyName = true)] 13 | [ValidateNotNullOrEmpty] 14 | [Alias("FullName")] 15 | public string[] Path 16 | { 17 | get { return paths.ToArray(); } 18 | set 19 | { 20 | paths.Clear(); 21 | paths.AddRange(value); 22 | } 23 | } 24 | 25 | protected override void BeginProcessing() 26 | { 27 | base.BeginProcessing(); 28 | 29 | if (paths.Count == 0) 30 | { 31 | paths.Add(GetVariableValue("PWD").ToString()); 32 | } 33 | } 34 | 35 | protected override void ProcessRecord() 36 | { 37 | FileSystemInfo item = null; 38 | 39 | foreach (var path in paths) 40 | { 41 | try 42 | { 43 | item = GetFileSystemInfo2(path); 44 | } 45 | catch (Exception ex) 46 | { 47 | WriteError(new ErrorRecord(ex, "ReadFileError", ErrorCategory.OpenError, path)); 48 | continue; 49 | } 50 | 51 | try 52 | { 53 | WriteObject(new FileSystemSecurity2(item)); 54 | } 55 | catch (UnauthorizedAccessException) 56 | { 57 | try 58 | { 59 | var ownerInfo = FileSystemOwner.GetOwner(item); 60 | var previousOwner = ownerInfo.Owner; 61 | 62 | FileSystemOwner.SetOwner(item, System.Security.Principal.WindowsIdentity.GetCurrent().User); 63 | 64 | WriteObject(new FileSystemSecurity2(item)); 65 | 66 | FileSystemOwner.SetOwner(item, previousOwner); 67 | } 68 | catch (Exception ex2) 69 | { 70 | WriteError(new ErrorRecord(ex2, "ReadSecurityError", ErrorCategory.WriteError, path)); 71 | continue; 72 | } 73 | } 74 | catch (Exception ex) 75 | { 76 | WriteError(new ErrorRecord(ex, "ReadSecurityError", ErrorCategory.OpenError, path)); 77 | } 78 | } 79 | } 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /NTFSSecurity/SecurityDescriptorCmdlets/SetSecurityDescriptor.cs: -------------------------------------------------------------------------------- 1 | using Security2; 2 | using System; 3 | using System.Management.Automation; 4 | 5 | namespace NTFSSecurity 6 | { 7 | [Cmdlet(VerbsCommon.Set, "NTFSSecurityDescriptor")] 8 | [OutputType(typeof(FileSystemSecurity2))] 9 | public class SetSecurityDescriptor : BaseCmdletWithPrivControl 10 | { 11 | private SwitchParameter passThru; 12 | 13 | [Parameter(Mandatory = true, Position = 2, ValueFromPipeline = true, ValueFromPipelineByPropertyName = true)] 14 | public FileSystemSecurity2[] SecurityDescriptor 15 | { 16 | get { return securityDescriptors.ToArray(); } 17 | set 18 | { 19 | securityDescriptors.Clear(); 20 | securityDescriptors.AddRange(value); 21 | } 22 | } 23 | 24 | [Parameter()] 25 | public SwitchParameter PassThru 26 | { 27 | get { return passThru; } 28 | set { passThru = value; } 29 | } 30 | 31 | protected override void BeginProcessing() 32 | { 33 | base.BeginProcessing(); 34 | } 35 | 36 | protected override void ProcessRecord() 37 | { 38 | foreach (var sd in securityDescriptors) 39 | { 40 | try 41 | { 42 | sd.Write(); 43 | 44 | if (passThru) 45 | { 46 | WriteObject(new FileSystemSecurity2(sd.Item)); 47 | } 48 | } 49 | catch (UnauthorizedAccessException) 50 | { 51 | try 52 | { 53 | var ownerInfo = FileSystemOwner.GetOwner(sd.Item); 54 | var previousOwner = ownerInfo.Owner; 55 | 56 | FileSystemOwner.SetOwner(sd.Item, System.Security.Principal.WindowsIdentity.GetCurrent().User); 57 | 58 | sd.Write(); 59 | 60 | FileSystemOwner.SetOwner(sd.Item, previousOwner); 61 | } 62 | catch (Exception ex2) 63 | { 64 | WriteError(new ErrorRecord(ex2, "WriteSdError", ErrorCategory.WriteError, sd.Item)); 65 | continue; 66 | } 67 | } 68 | catch (Exception ex) 69 | { 70 | WriteError(new ErrorRecord(ex, "WriteSdError", ErrorCategory.WriteError, sd.Item)); 71 | } 72 | } 73 | } 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /NTFSSecurity/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /NTFSSecurityTest/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("NTFSSecurityTest")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("NTFSSecurityTest")] 13 | [assembly: AssemblyCopyright("Copyright © 2016")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("675d40fa-f56c-4acc-b863-18b4a14f93e0")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /NTFSSecurityTest/Properties/Settings.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.42000 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace NTFSSecurityTest.Properties { 12 | 13 | 14 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 15 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "14.0.0.0")] 16 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { 17 | 18 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); 19 | 20 | public static Settings Default { 21 | get { 22 | return defaultInstance; 23 | } 24 | } 25 | 26 | [global::System.Configuration.UserScopedSettingAttribute()] 27 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 28 | [global::System.Configuration.DefaultSettingValueAttribute("d:\\UnitTest")] 29 | public string path { 30 | get { 31 | return ((string)(this["path"])); 32 | } 33 | set { 34 | this["path"] = value; 35 | } 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /NTFSSecurityTest/Properties/Settings.settings: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | d:\UnitTest 7 | 8 | 9 | -------------------------------------------------------------------------------- /NTFSSecurityTest/UnitTest1.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Microsoft.VisualStudio.TestTools.UnitTesting; 3 | using System.IO; 4 | using NTFSSecurityTest.Properties; 5 | 6 | namespace NTFSSecurityTest 7 | { 8 | [TestClass] 9 | public class UnitTest1 10 | { 11 | [TestMethod] 12 | public void TestMethod1() 13 | { 14 | Assert.IsTrue(Directory.Exists(Settings.Default.path + "1")); 15 | } 16 | 17 | [TestInitialize] 18 | public void Init() 19 | { 20 | System.Threading.Thread.Sleep(3000); 21 | Directory.CreateDirectory(Settings.Default.path); 22 | } 23 | 24 | [TestCleanup] 25 | public void Cleanup() 26 | { 27 | Directory.Delete(Settings.Default.path); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /NTFSSecurityTest/app.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 |
6 | 7 | 8 | 9 | 10 | 11 | d:\UnitTest 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /PrivilegeControl/PrivilegeControl.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Security.AccessControl; 3 | using ProcessPrivileges; 4 | using System.Diagnostics; 5 | 6 | namespace Security2 7 | { 8 | public class AdjustPriviledgeException : Exception 9 | { 10 | public AdjustPriviledgeException(string message) 11 | : base(message) 12 | { } 13 | } 14 | 15 | public class PrivilegeControl 16 | { 17 | private Process p; 18 | 19 | public PrivilegeControl() 20 | { 21 | p = Process.GetCurrentProcess(); 22 | } 23 | 24 | public PrivilegeAndAttributesCollection GetPrivileges() 25 | { 26 | return p.GetPrivileges(); 27 | } 28 | 29 | public AdjustPrivilegeResult EnablePrivilege(Privilege privilege) 30 | { 31 | if (p.GetPrivilegeState(privilege) == PrivilegeState.Disabled) 32 | { 33 | AdjustPrivilegeResult result = p.EnablePrivilege(privilege); 34 | return result; 35 | } 36 | else if (p.GetPrivilegeState(privilege) == PrivilegeState.Removed) 37 | { 38 | throw new PrivilegeNotHeldException(privilege.ToString()); 39 | } 40 | else if (p.GetPrivilegeState(privilege) == PrivilegeState.Enabled) 41 | { 42 | throw new AdjustPriviledgeException("Priviledge already enabled"); 43 | } 44 | else 45 | { 46 | throw new AdjustPriviledgeException("Unknown Error"); 47 | } 48 | } 49 | 50 | public AdjustPrivilegeResult DisablePrivilege(Privilege privilege) 51 | { 52 | if (p.GetPrivilegeState(privilege) == PrivilegeState.Enabled) 53 | { 54 | AdjustPrivilegeResult result = p.DisablePrivilege(privilege); 55 | return result; 56 | } 57 | else if (p.GetPrivilegeState(privilege) == PrivilegeState.Removed) 58 | { 59 | throw new PrivilegeNotHeldException(privilege.ToString()); 60 | } 61 | else if (p.GetPrivilegeState(privilege) == PrivilegeState.Disabled) 62 | { 63 | throw new AdjustPriviledgeException("Priviledge already disabled"); 64 | } 65 | else 66 | { 67 | throw new AdjustPriviledgeException("Unknown Error"); 68 | } 69 | } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /PrivilegeControl/PrivilegeControl.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Debug 5 | AnyCPU 6 | 8.0.30703 7 | 2.0 8 | {01EAB41B-B2CE-49FE-AB5A-0F0FF0A9A7EE} 9 | Library 10 | Properties 11 | PrivilegeControl 12 | PrivilegeControl 13 | v4.5.2 14 | 512 15 | 16 | 17 | SAK 18 | SAK 19 | SAK 20 | SAK 21 | 22 | 23 | true 24 | full 25 | false 26 | bin\Debug\ 27 | DEBUG;TRACE 28 | prompt 29 | 4 30 | false 31 | false 32 | 33 | 34 | pdbonly 35 | true 36 | bin\Release\ 37 | TRACE 38 | prompt 39 | 4 40 | false 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | {410CAEE5-D287-4A18-9B38-BB87397D218D} 57 | ProcessPrivileges 58 | 59 | 60 | 61 | 68 | -------------------------------------------------------------------------------- /PrivilegeControl/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("PrivilegeControl")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("Microsoft")] 12 | [assembly: AssemblyProduct("PrivilegeControl")] 13 | [assembly: AssemblyCopyright("Copyright © Microsoft 2011")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("a8bb93b7-f0f5-47a1-b552-819b653bb3b8")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /ProcessPrivileges/AccessTokenHandle.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright © Nick Lowe 2009 3 | // 4 | // Nick Lowe 5 | // nick@int-r.net 6 | // http://processprivileges.codeplex.com/ 7 | 8 | namespace ProcessPrivileges 9 | { 10 | using System.ComponentModel; 11 | using System.Runtime.ConstrainedExecution; 12 | using System.Runtime.InteropServices; 13 | using Microsoft.Win32.SafeHandles; 14 | 15 | /// Handle to an access token. 16 | public sealed class AccessTokenHandle : SafeHandleZeroOrMinusOneIsInvalid 17 | { 18 | internal AccessTokenHandle(ProcessHandle processHandle, TokenAccessRights tokenAccessRights) 19 | : base(true) 20 | { 21 | if (!NativeMethods.OpenProcessToken(processHandle, tokenAccessRights, ref handle)) 22 | { 23 | throw new Win32Exception(Marshal.GetLastWin32Error()); 24 | } 25 | } 26 | 27 | /// Releases the handle. 28 | /// Value indicating if the handle released successfully. 29 | [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)] 30 | protected override bool ReleaseHandle() 31 | { 32 | if (!NativeMethods.CloseHandle(handle)) 33 | { 34 | throw new Win32Exception(Marshal.GetLastWin32Error()); 35 | } 36 | 37 | return true; 38 | } 39 | } 40 | } -------------------------------------------------------------------------------- /ProcessPrivileges/AllocatedMemory.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright © Nick Lowe 2009 3 | // 4 | // Nick Lowe 5 | // nick@int-r.net 6 | // http://processprivileges.codeplex.com/ 7 | 8 | namespace ProcessPrivileges 9 | { 10 | using System; 11 | using System.Diagnostics.CodeAnalysis; 12 | using System.Runtime.InteropServices; 13 | 14 | internal sealed class AllocatedMemory : IDisposable 15 | { 16 | [SuppressMessage("Microsoft.Reliability", 17 | "CA2006:UseSafeHandleToEncapsulateNativeResources", 18 | Justification = "Not pointing to a native resource.")] 19 | private IntPtr pointer; 20 | 21 | internal AllocatedMemory(int bytesRequired) 22 | { 23 | this.pointer = Marshal.AllocHGlobal(bytesRequired); 24 | } 25 | 26 | ~AllocatedMemory() 27 | { 28 | this.InternalDispose(); 29 | } 30 | 31 | internal IntPtr Pointer 32 | { 33 | get 34 | { 35 | return this.pointer; 36 | } 37 | } 38 | 39 | public void Dispose() 40 | { 41 | this.InternalDispose(); 42 | GC.SuppressFinalize(this); 43 | } 44 | 45 | private void InternalDispose() 46 | { 47 | if (this.pointer != IntPtr.Zero) 48 | { 49 | Marshal.FreeHGlobal(this.pointer); 50 | this.pointer = IntPtr.Zero; 51 | } 52 | } 53 | } 54 | } -------------------------------------------------------------------------------- /ProcessPrivileges/NativeMethods.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright © Nick Lowe 2009 3 | // 4 | // Nick Lowe 5 | // nick@int-r.net 6 | // http://processprivileges.codeplex.com/ 7 | 8 | namespace ProcessPrivileges 9 | { 10 | using System; 11 | using System.Runtime.ConstrainedExecution; 12 | using System.Runtime.InteropServices; 13 | using System.Security; 14 | using System.Text; 15 | 16 | /// Static class containing Win32 native methods. 17 | internal static class NativeMethods 18 | { 19 | internal const int ErrorInsufficientBuffer = 122; 20 | 21 | private const string AdvApi32 = "advapi32.dll"; 22 | 23 | private const string Kernel32 = "kernel32.dll"; 24 | 25 | [DllImport(AdvApi32, SetLastError = true), 26 | SuppressUnmanagedCodeSecurity] 27 | [return: MarshalAs(UnmanagedType.Bool)] 28 | internal static extern bool AdjustTokenPrivileges( 29 | [In] AccessTokenHandle accessTokenHandle, 30 | [In, MarshalAs(UnmanagedType.Bool)] bool disableAllPrivileges, 31 | [In] ref TokenPrivilege newState, 32 | [In] int bufferLength, 33 | [In, Out] ref TokenPrivilege previousState, 34 | [In, Out] ref int returnLength); 35 | 36 | [DllImport(Kernel32, SetLastError = true), 37 | ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail), 38 | SuppressUnmanagedCodeSecurity] 39 | [return: MarshalAs(UnmanagedType.Bool)] 40 | internal static extern bool CloseHandle( 41 | [In] IntPtr handle); 42 | 43 | [DllImport(AdvApi32, CharSet = CharSet.Unicode, SetLastError = true), 44 | SuppressUnmanagedCodeSecurity] 45 | [return: MarshalAs(UnmanagedType.Bool)] 46 | internal static extern bool LookupPrivilegeName( 47 | [In] string systemName, 48 | [In] ref Luid luid, 49 | [In, Out] StringBuilder name, 50 | [In, Out] ref int nameLength); 51 | 52 | [DllImport(AdvApi32, CharSet = CharSet.Unicode, SetLastError = true), 53 | SuppressUnmanagedCodeSecurity] 54 | [return: MarshalAs(UnmanagedType.Bool)] 55 | internal static extern bool LookupPrivilegeValue( 56 | [In] string systemName, 57 | [In] string name, 58 | [In, Out] ref Luid luid); 59 | 60 | [DllImport(AdvApi32, SetLastError = true), 61 | SuppressUnmanagedCodeSecurity] 62 | [return: MarshalAs(UnmanagedType.Bool)] 63 | internal static extern bool GetTokenInformation( 64 | [In] AccessTokenHandle accessTokenHandle, 65 | [In] TokenInformationClass tokenInformationClass, 66 | [Out] IntPtr tokenInformation, 67 | [In] int tokenInformationLength, 68 | [In, Out] ref int returnLength); 69 | 70 | [DllImport(AdvApi32, SetLastError = true), 71 | SuppressUnmanagedCodeSecurity] 72 | [return: MarshalAs(UnmanagedType.Bool)] 73 | internal static extern bool OpenProcessToken( 74 | [In] ProcessHandle processHandle, 75 | [In] TokenAccessRights desiredAccess, 76 | [In, Out] ref IntPtr tokenHandle); 77 | } 78 | } -------------------------------------------------------------------------------- /ProcessPrivileges/NativeStructs.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright © Nick Lowe 2009 3 | // 4 | // Nick Lowe 5 | // nick@int-r.net 6 | // http://processprivileges.codeplex.com/ 7 | 8 | namespace ProcessPrivileges 9 | { 10 | using System.Runtime.InteropServices; 11 | 12 | [StructLayout(LayoutKind.Sequential)] 13 | internal struct Luid 14 | { 15 | internal int LowPart; 16 | 17 | internal int HighPart; 18 | } 19 | 20 | [StructLayout(LayoutKind.Sequential)] 21 | internal struct LuidAndAttributes 22 | { 23 | internal Luid Luid; 24 | 25 | internal PrivilegeAttributes Attributes; 26 | } 27 | 28 | [StructLayout(LayoutKind.Sequential)] 29 | internal struct TokenPrivilege 30 | { 31 | internal int PrivilegeCount; 32 | 33 | internal LuidAndAttributes Privilege; 34 | } 35 | } -------------------------------------------------------------------------------- /ProcessPrivileges/PrivilegeAndAttributesCollection.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright © Nick Lowe 2009 3 | // 4 | // Nick Lowe 5 | // nick@int-r.net 6 | // http://processprivileges.codeplex.com/ 7 | 8 | namespace ProcessPrivileges 9 | { 10 | using System; 11 | using System.Collections.Generic; 12 | using System.Collections.ObjectModel; 13 | using System.Linq; 14 | using System.Text; 15 | 16 | /// Read-only collection of privilege and attributes. 17 | [Serializable] 18 | public sealed class PrivilegeAndAttributesCollection : ReadOnlyCollection 19 | { 20 | internal PrivilegeAndAttributesCollection(IList list) 21 | : base(list) 22 | { 23 | } 24 | 25 | /// Returns a representation of the collection. 26 | /// representation of the collection. 27 | public override string ToString() 28 | { 29 | StringBuilder stringBuilder = new StringBuilder(); 30 | int maxPrivilegeLength = this.Max(privilegeAndAttributes => privilegeAndAttributes.Privilege.ToString().Length); 31 | foreach (PrivilegeAndAttributes privilegeAndAttributes in this) 32 | { 33 | stringBuilder.Append(privilegeAndAttributes.Privilege); 34 | int paddingLength = maxPrivilegeLength - privilegeAndAttributes.Privilege.ToString().Length; 35 | char[] padding = new char[paddingLength]; 36 | for (int i = 0; i < paddingLength; i++) 37 | { 38 | padding[i] = ' '; 39 | } 40 | 41 | stringBuilder.Append(padding); 42 | stringBuilder.Append(" => "); 43 | stringBuilder.AppendLine(privilegeAndAttributes.PrivilegeAttributes.ToString()); 44 | } 45 | 46 | return stringBuilder.ToString(); 47 | } 48 | } 49 | } -------------------------------------------------------------------------------- /ProcessPrivileges/ProcessHandle.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright © Nick Lowe 2009 3 | // 4 | // Nick Lowe 5 | // nick@int-r.net 6 | // http://processprivileges.codeplex.com/ 7 | 8 | namespace ProcessPrivileges 9 | { 10 | using System; 11 | using System.ComponentModel; 12 | using System.Runtime.ConstrainedExecution; 13 | using System.Runtime.InteropServices; 14 | using Microsoft.Win32.SafeHandles; 15 | 16 | internal sealed class ProcessHandle : SafeHandleZeroOrMinusOneIsInvalid 17 | { 18 | internal ProcessHandle(IntPtr processHandle, bool ownsHandle) 19 | : base(ownsHandle) 20 | { 21 | handle = processHandle; 22 | } 23 | 24 | [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)] 25 | protected override bool ReleaseHandle() 26 | { 27 | if (!NativeMethods.CloseHandle(handle)) 28 | { 29 | throw new Win32Exception(Marshal.GetLastWin32Error()); 30 | } 31 | 32 | return true; 33 | } 34 | } 35 | } -------------------------------------------------------------------------------- /ProcessPrivileges/ProcessPrivileges.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Debug 5 | AnyCPU 6 | 9.0.30729 7 | 2.0 8 | {410CAEE5-D287-4A18-9B38-BB87397D218D} 9 | Library 10 | Properties 11 | ProcessPrivileges 12 | ProcessPrivileges 13 | v4.5.2 14 | 512 15 | false 16 | 17 | 18 | 19 | 20 | 3.5 21 | 22 | SAK 23 | SAK 24 | SAK 25 | SAK 26 | 27 | 28 | 29 | 30 | true 31 | full 32 | false 33 | bin\Debug\ 34 | DEBUG;TRACE 35 | prompt 36 | 4 37 | AllRules.ruleset 38 | false 39 | false 40 | 41 | 42 | pdbonly 43 | true 44 | bin\Release\ 45 | TRACE 46 | prompt 47 | 4 48 | bin\Release\ProcessPrivileges.XML 49 | true 50 | AllRules.ruleset 51 | false 52 | 53 | 54 | 55 | 56 | 3.5 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 82 | -------------------------------------------------------------------------------- /ProcessPrivileges/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright © Nick Lowe 2009 3 | // 4 | // Nick Lowe 5 | // nick@int-r.net 6 | // http://processprivileges.codeplex.com/ 7 | 8 | using System.Reflection; 9 | using System.Runtime.CompilerServices; 10 | using System.Runtime.InteropServices; 11 | 12 | // General Information about an assembly is controlled through the following 13 | // set of attributes. Change these attribute values to modify the information 14 | // associated with an assembly. 15 | [assembly: AssemblyTitle("Process Privileges")] 16 | [assembly: AssemblyDescription("Implements the functionality necessary to query, enable, disable or remove privileges on a process.")] 17 | [assembly: AssemblyConfiguration("")] 18 | [assembly: AssemblyCompany("")] 19 | [assembly: AssemblyProduct("Process Privileges")] 20 | [assembly: AssemblyCopyright("Copyright © Nick Lowe 2009")] 21 | [assembly: AssemblyTrademark("")] 22 | [assembly: AssemblyCulture("")] 23 | 24 | // Setting ComVisible to false makes the types in this assembly not visible 25 | // to COM components. If you need to access a type in this assembly from 26 | // COM, set the ComVisible attribute to true on that type. 27 | [assembly: ComVisible(false)] 28 | 29 | // The following GUID is for the ID of the typelib if this project is exposed to COM 30 | [assembly: Guid("9ba57646-7a83-4f21-b555-92f1463c9f3e")] 31 | 32 | // Version information for an assembly consists of the following four values: 33 | // 34 | // Major Version 35 | // Minor Version 36 | // Build Number 37 | // Revision 38 | // 39 | // You can specify all the values or you can default the Build and Revision Numbers 40 | // by using the '*' as shown below: 41 | // [assembly: AssemblyVersion("1.0.*")] 42 | [assembly: AssemblyVersion("1.5.7.0")] 43 | [assembly: AssemblyFileVersion("1.5.7.0")] 44 | 45 | [assembly: System.CLSCompliant(true)] 46 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ### Summary 2 | Managing permissions with PowerShell is only a bit easier than in VBS or the command line as there are no cmdlets for most day-to-day tasks like getting a permission report or adding permission to an item. PowerShell only offers Get-Acl and Set-Acl but everything in between getting and setting the ACL is missing. This module closes the gap. 3 | 4 | ### [Version History](https://github.com/raandree/NTFSSecurity/wiki/Version-History) 5 | 6 | ### Installation 7 | You have two options: 8 | 1. Download the latest release from [the releases section](https://github.com/raandree/NTFSSecurity/releases). 9 | 2. Download the module from the [PowerShell Gallery](https://www.powershellgallery.com/packages/NTFSSecurity): Install-Module -Name NTFSSecurity 10 | 11 | Further help can be found in [How to install](https://github.com/raandree/NTFSSecurity/wiki/How-to-install) if you face difficulties getting this module installed. 12 | 13 | ### Documentation 14 | The cmdlets are documented in Docs/. 15 | They are not documented completely so Get-Help will not show help for all the cmdlets. Providing documentation is planned though. 16 | 17 | See [Examples](Docs/Examples.md) for some usage examples. 18 | 19 | Additional documentation is available: 20 | * [NTFSSecurity Tutorial 1 - Getting, adding and removing permissions](https://docs.microsoft.com/en-us/archive/blogs/fieldcoding/ntfssecurity-tutorial-1-getting-adding-and-removing-permissions) 21 | * [NTFSSecurity Tutorial 2 - Managing NTFS Inheritance and Using Privileges](https://docs.microsoft.com/en-us/archive/blogs/fieldcoding/ntfssecurity-tutorial-2-managing-ntfs-inheritance-and-using-privileges) 22 | -------------------------------------------------------------------------------- /Security2/EffectiveAccess.cs: -------------------------------------------------------------------------------- 1 | using Alphaleonis.Win32.Filesystem; 2 | using System; 3 | using System.Security.AccessControl; 4 | using System.Security.Principal; 5 | 6 | namespace Security2 7 | { 8 | public class EffectiveAccess 9 | { 10 | public static EffectiveAccessInfo GetEffectiveAccess(FileSystemInfo item, IdentityReference2 id, string serverName) 11 | { 12 | bool remoteServerAvailable = false; 13 | Exception authzAccessCheckException = null; 14 | 15 | var win32 = new Win32(); 16 | 17 | var fss = new FileSystemSecurity2(item); 18 | 19 | var effectiveAccessMask = win32.GetEffectiveAccess(fss.SecurityDescriptor, id, serverName, out remoteServerAvailable, out authzAccessCheckException); 20 | 21 | var ace = new FileSystemAccessRule((SecurityIdentifier)id, (FileSystemRights)effectiveAccessMask, AccessControlType.Allow); 22 | 23 | return new EffectiveAccessInfo( 24 | new FileSystemAccessRule2(ace, item), 25 | remoteServerAvailable, 26 | authzAccessCheckException); 27 | } 28 | } 29 | 30 | public class EffectiveAccessInfo 31 | { 32 | private FileSystemAccessRule2 ace; 33 | private bool fromRemote; 34 | private Exception authzException; 35 | 36 | public FileSystemAccessRule2 Ace 37 | { 38 | get { return ace; } 39 | } 40 | 41 | public bool FromRemote 42 | { 43 | get { return fromRemote; } 44 | } 45 | 46 | public Exception AuthzException 47 | { 48 | get { return authzException; } 49 | } 50 | 51 | public bool OperationFailed 52 | { 53 | get 54 | { 55 | return authzException == null ? false : true; 56 | } 57 | } 58 | 59 | public EffectiveAccessInfo(FileSystemAccessRule2 ace, bool fromRemote, Exception authzException = null) 60 | { 61 | this.ace = ace; 62 | this.fromRemote = fromRemote; 63 | this.authzException = authzException; 64 | } 65 | } 66 | } -------------------------------------------------------------------------------- /Security2/Enums.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Security.AccessControl; 3 | 4 | namespace Security2 5 | { 6 | public enum ApplyTo 7 | { 8 | ThisFolderOnly, //InheritanceFlags None / PropagationFlags None 9 | 10 | ThisFolderSubfoldersAndFiles, //InheritanceFlags ContainerInherit, ObjectInherit / PropagationFlags None 11 | ThisFolderAndSubfolders, //InheritanceFlags ContainerInherit / PropagationFlags None 12 | ThisFolderAndFiles, //InheritanceFlags ObjectInherit / PropagationFlags None 13 | SubfoldersAndFilesOnly, //InheritanceFlags ContainerInherit, ObjectInherit / PropagationFlags InheritOnly 14 | SubfoldersOnly, //InheritanceFlags ContainerInherit / PropagationFlags InheritOnly 15 | FilesOnly, //InheritanceFlags ObjectInherit / PropagationFlags InheritOnly 16 | 17 | ThisFolderSubfoldersAndFilesOneLevel, //InheritanceFlags ContainerInherit, ObjectInherit / PropagationFlags NoPropagateInherit 18 | ThisFolderAndSubfoldersOneLevel, //InheritanceFlags ContainerInherit / PropagationFlags NoPropagateInherit 19 | ThisFolderAndFilesOneLevel, //InheritanceFlags ObjectInherit / PropagationFlags NoPropagateInherit 20 | SubfoldersAndFilesOnlyOneLevel, //InheritanceFlags ContainerInherit, ObjectInherit / PropagationFlags InheritOnly, NoPropagateInherit 21 | SubfoldersOnlyOneLevel, //InheritanceFlags ContainerInherit / PropagationFlags InheritOnly, NoPropagateInherit 22 | FilesOnlyOneLevel, //InheritanceFlags ObjectInherit / PropagationFlags InheritOnly, NoPropagateInherit 23 | } 24 | 25 | [Flags] 26 | public enum FileSystemRights2 : uint 27 | { 28 | None = 0, 29 | ListDirectory = 1, 30 | ReadData = 1, 31 | WriteData = 2, 32 | CreateFiles = 2, 33 | CreateDirectories = 4, 34 | AppendData = 4, 35 | ReadExtendedAttributes = 8, 36 | WriteExtendedAttributes = 16, 37 | ExecuteFile = 32, 38 | Traverse = 32, 39 | DeleteSubdirectoriesAndFiles = 64, 40 | ReadAttributes = 128, 41 | WriteAttributes = 256, 42 | Write = 278, 43 | Delete = 65536, 44 | ReadPermissions = 131072, 45 | Read = 131209, 46 | ReadAndExecute = 131241, 47 | Modify = 197055, 48 | ChangePermissions = 262144, 49 | TakeOwnership = 524288, 50 | Synchronize = 1048576, 51 | FullControl = 2032127, 52 | GenericRead = 0x80000000, 53 | GenericWrite = 0x40000000, 54 | GenericExecute = 0x20000000, 55 | GenericAll = 0x10000000 56 | } 57 | 58 | [Flags] 59 | public enum SimpleFileSystemAccessRights 60 | { 61 | None = 0, 62 | Read = 1, 63 | Write = 2, 64 | Delete = 4 65 | } 66 | 67 | public enum GenericRights : uint 68 | { 69 | GENERIC_READ = 0x80000000, 70 | GENERIC_WRITE = 0x40000000, 71 | GENERIC_EXECUTE = 0x20000000, 72 | GENERIC_ALL = 0x10000000 73 | } 74 | 75 | public enum MappedGenericRights : uint 76 | { 77 | FILE_GENERIC_EXECUTE = FileSystemRights.ExecuteFile | FileSystemRights.ReadPermissions | FileSystemRights.ReadAttributes | FileSystemRights.Synchronize, 78 | FILE_GENERIC_READ = FileSystemRights.ReadAttributes | FileSystemRights.ReadData | FileSystemRights.ReadExtendedAttributes | FileSystemRights.ReadPermissions | FileSystemRights.Synchronize, 79 | FILE_GENERIC_WRITE = FileSystemRights.AppendData | FileSystemRights.WriteAttributes | FileSystemRights.WriteData | FileSystemRights.WriteExtendedAttributes | FileSystemRights.ReadPermissions | FileSystemRights.Synchronize, 80 | FILE_GENERIC_ALL = FileSystemRights.FullControl 81 | } 82 | } -------------------------------------------------------------------------------- /Security2/Exceptions/Exceptions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Security2 4 | { 5 | public class RightsConverionException : Exception 6 | { 7 | public RightsConverionException(string Message) : base(Message) { } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Security2/Extensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | 4 | namespace Security2 5 | { 6 | internal static class IntPtrExtensions 7 | { 8 | public static IntPtr Increment(this IntPtr ptr, int cbSize) 9 | { 10 | return new IntPtr(ptr.ToInt64() + cbSize); 11 | } 12 | 13 | public static IntPtr Increment(this IntPtr ptr) 14 | { 15 | return ptr.Increment(Marshal.SizeOf(typeof(T))); 16 | } 17 | 18 | public static T ElementAt(this IntPtr ptr, int index) 19 | { 20 | var offset = Marshal.SizeOf(typeof(T)) * index; 21 | var offsetPtr = ptr.Increment(offset); 22 | return (T)Marshal.PtrToStructure(offsetPtr, typeof(T)); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Security2/FileSystem/FileInfo/Extensions.cs: -------------------------------------------------------------------------------- 1 | using System.Text; 2 | 3 | namespace Security2.FileSystem.FileInfo 4 | { 5 | public enum HashAlgorithms 6 | { 7 | SHA1, 8 | SHA256, 9 | SHA384, 10 | SHA512, 11 | MACTripleDES, 12 | MD5, 13 | RIPEMD160 14 | } 15 | 16 | public static class Extensions 17 | { 18 | 19 | public static string GetHash(this Alphaleonis.Win32.Filesystem.FileInfo file, HashAlgorithms algorithm) 20 | { 21 | byte[] hash = null; 22 | 23 | using (var fileStream = file.OpenRead()) 24 | { 25 | switch (algorithm) 26 | { 27 | case HashAlgorithms.MD5: 28 | hash = System.Security.Cryptography.MD5.Create().ComputeHash(fileStream); 29 | break; 30 | case HashAlgorithms.SHA1: 31 | hash = System.Security.Cryptography.SHA1.Create().ComputeHash(fileStream); 32 | break; 33 | case HashAlgorithms.SHA256: 34 | hash = System.Security.Cryptography.SHA256.Create().ComputeHash(fileStream); 35 | break; 36 | case HashAlgorithms.SHA384: 37 | hash = System.Security.Cryptography.SHA384.Create().ComputeHash(fileStream); 38 | break; 39 | case HashAlgorithms.SHA512: 40 | hash = System.Security.Cryptography.SHA512.Create().ComputeHash(fileStream); 41 | break; 42 | case HashAlgorithms.MACTripleDES: 43 | hash = System.Security.Cryptography.MACTripleDES.Create().ComputeHash(fileStream); 44 | break; 45 | case HashAlgorithms.RIPEMD160: 46 | hash = System.Security.Cryptography.RIPEMD160.Create().ComputeHash(fileStream); 47 | break; 48 | } 49 | 50 | fileStream.Close(); 51 | } 52 | 53 | var sb = new StringBuilder(hash.Length); 54 | for (var i = 0; i < hash.Length; i++) 55 | { 56 | sb.Append(hash[i].ToString("X2")); 57 | } 58 | 59 | return sb.ToString(); 60 | } 61 | } 62 | } -------------------------------------------------------------------------------- /Security2/FileSystem/FileSystemAccessRule2 Class/FileSystemAccessRule2.GetFileSystemAccessRules.cs: -------------------------------------------------------------------------------- 1 | using Alphaleonis.Win32.Filesystem; 2 | using System.Collections.Generic; 3 | using System.Security.AccessControl; 4 | using System.Security.Principal; 5 | 6 | namespace Security2 7 | { 8 | public partial class FileSystemAccessRule2 9 | { 10 | public static IEnumerable GetFileSystemAccessRules(FileSystemInfo item, bool includeExplicit, bool includeInherited, bool getInheritedFrom = false) 11 | { 12 | var sd = new FileSystemSecurity2(item, AccessControlSections.Access); 13 | 14 | return GetFileSystemAccessRules(sd, includeExplicit, includeInherited, getInheritedFrom); 15 | } 16 | 17 | public static IEnumerable GetFileSystemAccessRules(FileSystemSecurity2 sd, bool includeExplicit, bool includeInherited, bool getInheritedFrom = false) 18 | { 19 | List aceList = new List(); 20 | List inheritedFrom = null; 21 | 22 | if (getInheritedFrom) 23 | { 24 | inheritedFrom = Win32.GetInheritedFrom(sd.Item, sd.SecurityDescriptor); 25 | } 26 | 27 | var aceCounter = 0; 28 | var acl = !sd.IsFile ? 29 | ((DirectorySecurity)sd.SecurityDescriptor).GetAccessRules(includeExplicit, includeInherited, typeof(SecurityIdentifier)) : 30 | ((FileSecurity)sd.SecurityDescriptor).GetAccessRules(includeExplicit, includeInherited, typeof(SecurityIdentifier)); 31 | 32 | foreach (FileSystemAccessRule ace in acl) 33 | { 34 | var ace2 = new FileSystemAccessRule2(ace) { FullName = sd.Item.FullName, InheritanceEnabled = !sd.SecurityDescriptor.AreAccessRulesProtected }; 35 | if (getInheritedFrom && inheritedFrom.Count > 0) 36 | { 37 | ace2.inheritedFrom = string.IsNullOrEmpty(inheritedFrom[aceCounter]) ? "" : inheritedFrom[aceCounter].Substring(0, inheritedFrom[aceCounter].Length - 1); 38 | aceCounter++; 39 | } 40 | 41 | aceList.Add(ace2); 42 | } 43 | 44 | return aceList; 45 | } 46 | 47 | public static IEnumerable GetFileSystemAccessRules(string path, bool includeExplicit, bool includeInherited, bool getInheritedFrom = false) 48 | { 49 | if (File.Exists(path)) 50 | { 51 | return GetFileSystemAccessRules(new FileInfo(path), includeExplicit, includeInherited, getInheritedFrom); 52 | } 53 | else 54 | { 55 | return GetFileSystemAccessRules(new DirectoryInfo(path), includeExplicit, includeInherited, getInheritedFrom); 56 | } 57 | } 58 | } 59 | } -------------------------------------------------------------------------------- /Security2/FileSystem/FileSystemAccessRule2 Class/FileSystemAccessRule2.RemoveFileSystemAccessRulesAll.cs: -------------------------------------------------------------------------------- 1 | using Alphaleonis.Win32.Filesystem; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Security.AccessControl; 5 | using System.Security.Principal; 6 | 7 | namespace Security2 8 | { 9 | public partial class FileSystemAccessRule2 10 | { 11 | public static void RemoveFileSystemAccessRuleAll(FileSystemSecurity2 sd, List accounts = null) 12 | { 13 | var acl = sd.SecurityDescriptor.GetAccessRules(true, false, typeof(SecurityIdentifier)); 14 | 15 | if (accounts != null) 16 | { 17 | acl.OfType().Where(ace => (accounts.Where(account => account == (IdentityReference2)ace.IdentityReference).Count() > 1)); 18 | } 19 | 20 | foreach (FileSystemAccessRule ace in acl) 21 | { 22 | sd.SecurityDescriptor.RemoveAccessRuleSpecific(ace); 23 | } 24 | } 25 | 26 | public static void RemoveFileSystemAccessRuleAll(FileSystemInfo item, List accounts = null) 27 | { 28 | var sd = new FileSystemSecurity2(item); 29 | 30 | RemoveFileSystemAccessRuleAll(sd, accounts); 31 | 32 | sd.Write(); 33 | } 34 | } 35 | } -------------------------------------------------------------------------------- /Security2/FileSystem/FileSystemAccessRule2 Class/FileSystemAccessRule2.cs: -------------------------------------------------------------------------------- 1 | using Alphaleonis.Win32.Filesystem; 2 | using System.Security.AccessControl; 3 | 4 | namespace Security2 5 | { 6 | public partial class FileSystemAccessRule2 7 | { 8 | #region Properties 9 | private FileSystemAccessRule fileSystemAccessRule; 10 | private string fullName; 11 | private bool inheritanceEnabled; 12 | private string inheritedFrom; 13 | 14 | public string Name { get { return System.IO.Path.GetFileName(fullName); } } 15 | public string FullName { get { return fullName; } set { fullName = value; } } 16 | public bool InheritanceEnabled { get { return inheritanceEnabled; } set { inheritanceEnabled = value; } } 17 | public string InheritedFrom { get { return inheritedFrom; } set { inheritedFrom = value; } } 18 | public AccessControlType AccessControlType { get { return fileSystemAccessRule.AccessControlType; } } 19 | public FileSystemRights2 AccessRights { get { return (FileSystemRights2)fileSystemAccessRule.FileSystemRights; } } 20 | public IdentityReference2 Account { get { return fileSystemAccessRule.IdentityReference; } } 21 | public InheritanceFlags InheritanceFlags { get { return fileSystemAccessRule.InheritanceFlags; } } 22 | public bool IsInherited { get { return fileSystemAccessRule.IsInherited; } } 23 | public PropagationFlags PropagationFlags { get { return fileSystemAccessRule.PropagationFlags; } } 24 | #endregion 25 | 26 | public FileSystemAccessRule2(FileSystemAccessRule fileSystemAccessRule) 27 | { 28 | this.fileSystemAccessRule = fileSystemAccessRule; 29 | } 30 | 31 | public FileSystemAccessRule2(FileSystemAccessRule fileSystemAccessRule, FileSystemInfo item) 32 | { 33 | this.fileSystemAccessRule = fileSystemAccessRule; 34 | this.fullName = item.FullName; 35 | } 36 | 37 | public FileSystemAccessRule2(FileSystemAccessRule fileSystemAccessRule, string path) 38 | { 39 | this.fileSystemAccessRule = fileSystemAccessRule; 40 | } 41 | 42 | public static implicit operator FileSystemAccessRule(FileSystemAccessRule2 ace2) 43 | { 44 | return ace2.fileSystemAccessRule; 45 | } 46 | public static implicit operator FileSystemAccessRule2(FileSystemAccessRule ace) 47 | { 48 | return new FileSystemAccessRule2(ace); 49 | } 50 | 51 | //REQUIRED BECAUSE OF CONVERSION OPERATORS 52 | public override bool Equals(object obj) 53 | { 54 | return fileSystemAccessRule == (FileSystemAccessRule)obj; 55 | } 56 | public override int GetHashCode() 57 | { 58 | return fileSystemAccessRule.GetHashCode(); 59 | } 60 | public override string ToString() 61 | { 62 | return string.Format("{0} '{1}' ({2})", 63 | AccessControlType.ToString()[0], 64 | Account.AccountName, 65 | AccessRights.ToString() 66 | ); 67 | 68 | } 69 | public SimpleFileSystemAccessRule ToSimpleFileSystemAccessRule2() 70 | { 71 | return new SimpleFileSystemAccessRule(fullName, Account, AccessRights, AccessControlType); 72 | } 73 | } 74 | } -------------------------------------------------------------------------------- /Security2/FileSystem/FileSystemAuditRule2 Class/FileSystemAuditRule2.GetFileSystemAuditRules.cs: -------------------------------------------------------------------------------- 1 | using Alphaleonis.Win32.Filesystem; 2 | using System.Collections.Generic; 3 | using System.Security.AccessControl; 4 | using System.Security.Principal; 5 | 6 | namespace Security2 7 | { 8 | public partial class FileSystemAuditRule2 9 | { 10 | public static IEnumerable GetFileSystemAuditRules(FileSystemInfo item, bool includeExplicit, bool includeInherited, bool getInheritedFrom = false) 11 | { 12 | var sd = new FileSystemSecurity2(item); 13 | 14 | return GetFileSystemAuditRules(sd, includeExplicit, includeInherited, getInheritedFrom); 15 | } 16 | 17 | public static IEnumerable GetFileSystemAuditRules(FileSystemSecurity2 sd, bool includeExplicit, bool includeInherited, bool getInheritedFrom = false) 18 | { 19 | List aceList = new List(); 20 | List inheritedFrom = null; 21 | 22 | if (getInheritedFrom) 23 | { 24 | inheritedFrom = Win32.GetInheritedFrom(sd.Item, sd.SecurityDescriptor); 25 | } 26 | 27 | var aceCounter = 0; 28 | var acl = !sd.IsFile ? 29 | ((DirectorySecurity)sd.SecurityDescriptor).GetAuditRules(includeExplicit, includeInherited, typeof(SecurityIdentifier)) : 30 | ((FileSecurity)sd.SecurityDescriptor).GetAuditRules(includeExplicit, includeInherited, typeof(SecurityIdentifier)); 31 | 32 | foreach (FileSystemAuditRule ace in acl) 33 | { 34 | var ace2 = new FileSystemAuditRule2(ace) { FullName = sd.Item.FullName, InheritanceEnabled = !sd.SecurityDescriptor.AreAccessRulesProtected }; 35 | if (getInheritedFrom) 36 | { 37 | ace2.inheritedFrom = string.IsNullOrEmpty(inheritedFrom[aceCounter]) ? "" : inheritedFrom[aceCounter].Substring(0, inheritedFrom[aceCounter].Length - 1); 38 | aceCounter++; 39 | } 40 | 41 | aceList.Add(ace2); 42 | } 43 | 44 | return aceList; 45 | } 46 | 47 | public static IEnumerable GetFileSystemAuditRules(string path, bool includeExplicit, bool includeInherited) 48 | { 49 | if (File.Exists(path)) 50 | { 51 | var item = new FileInfo(path); 52 | return GetFileSystemAuditRules(item, includeExplicit, includeInherited); 53 | } 54 | else 55 | { 56 | var item = new DirectoryInfo(path); 57 | return GetFileSystemAuditRules(item, includeExplicit, includeInherited); 58 | } 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /Security2/FileSystem/FileSystemAuditRule2 Class/FileSystemAuditRule2.RemoveFileSystemAuditRuleAll.cs: -------------------------------------------------------------------------------- 1 | using Alphaleonis.Win32.Filesystem; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Security.AccessControl; 5 | using System.Security.Principal; 6 | 7 | namespace Security2 8 | { 9 | public partial class FileSystemAuditRule2 10 | { 11 | public static void RemoveFileSystemAuditRuleAll(FileSystemSecurity2 sd, List accounts = null) 12 | { 13 | var acl = sd.SecurityDescriptor.GetAuditRules(true, false, typeof(SecurityIdentifier)); 14 | 15 | if (accounts != null) 16 | { 17 | acl.OfType().Where(ace => (accounts.Where(account => account == (IdentityReference2)ace.IdentityReference).Count() > 1)); 18 | } 19 | 20 | foreach (FileSystemAuditRule ace in acl) 21 | { 22 | sd.SecurityDescriptor.RemoveAuditRuleSpecific(ace); 23 | } 24 | } 25 | 26 | public static void RemoveFileSystemAuditRuleAll(FileSystemInfo item, List accounts = null) 27 | { 28 | var sd = new FileSystemSecurity2(item); 29 | 30 | RemoveFileSystemAuditRuleAll(sd, accounts); 31 | 32 | sd.Write(); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Security2/FileSystem/FileSystemAuditRule2 Class/FileSystemAuditRule2.cs: -------------------------------------------------------------------------------- 1 | using Alphaleonis.Win32.Filesystem; 2 | using System.Security.AccessControl; 3 | 4 | namespace Security2 5 | { 6 | public partial class FileSystemAuditRule2 7 | { 8 | #region Properties 9 | private FileSystemAuditRule fileSystemAuditRule; 10 | private string fullName; 11 | private bool inheritanceEnabled; 12 | private string inheritedFrom; 13 | 14 | public string Name { get { return System.IO.Path.GetFileName(fullName); } } 15 | public string FullName { get { return fullName; } set { fullName = value; } } 16 | public bool InheritanceEnabled { get { return inheritanceEnabled; } set { inheritanceEnabled = value; } } 17 | public string InheritedFrom { get { return inheritedFrom; } set { inheritedFrom = value; } } 18 | public AuditFlags AuditFlags { get { return fileSystemAuditRule.AuditFlags; } } 19 | public FileSystemRights2 AccessRights { get { return (FileSystemRights2)fileSystemAuditRule.FileSystemRights; } } 20 | public IdentityReference2 Account { get { return (IdentityReference2)fileSystemAuditRule.IdentityReference; } } 21 | public InheritanceFlags InheritanceFlags { get { return fileSystemAuditRule.InheritanceFlags; } } 22 | public bool IsInherited { get { return fileSystemAuditRule.IsInherited; } } 23 | public PropagationFlags PropagationFlags { get { return fileSystemAuditRule.PropagationFlags; } } 24 | #endregion 25 | 26 | public FileSystemAuditRule2(FileSystemAuditRule fileSystemAuditRule) 27 | { 28 | this.fileSystemAuditRule = fileSystemAuditRule; 29 | } 30 | 31 | public FileSystemAuditRule2(FileSystemAuditRule fileSystemAuditRule, FileSystemInfo item) 32 | { 33 | this.fileSystemAuditRule = fileSystemAuditRule; 34 | this.fullName = item.FullName; 35 | } 36 | 37 | public FileSystemAuditRule2(FileSystemAuditRule fileSystemAuditRule, string path) 38 | { 39 | this.fileSystemAuditRule = fileSystemAuditRule; 40 | } 41 | 42 | #region Conversion 43 | public static implicit operator FileSystemAuditRule(FileSystemAuditRule2 ace2) 44 | { 45 | return ace2.fileSystemAuditRule; 46 | } 47 | public static implicit operator FileSystemAuditRule2(FileSystemAuditRule ace) 48 | { 49 | return new FileSystemAuditRule2(ace); 50 | } 51 | //REQUIRED BECAUSE OF CONVERSION OPERATORS 52 | public override bool Equals(object obj) 53 | { 54 | return this.fileSystemAuditRule == (FileSystemAuditRule)obj; 55 | } 56 | public override int GetHashCode() 57 | { 58 | return this.fileSystemAuditRule.GetHashCode(); 59 | } 60 | public override string ToString() 61 | { 62 | return fileSystemAuditRule.ToString(); 63 | } 64 | public SimpleFileSystemAuditRule ToSimpleFileSystemAuditRule2() 65 | { 66 | return new SimpleFileSystemAuditRule(this.fullName, this.Account, this.AccessRights); 67 | } 68 | #endregion 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /Security2/FileSystem/FileSystemEffectivePermissionEntry.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Security.AccessControl; 3 | 4 | namespace Security2 5 | { 6 | public class FileSystemEffectivePermissionEntry 7 | { 8 | private IdentityReference2 account; 9 | private uint accessMask; 10 | private string objectPath; 11 | 12 | public IdentityReference2 Account { get { return account; } } 13 | 14 | public uint AccessMask { get { return accessMask; } } 15 | 16 | public string FullName { get { return objectPath; } } 17 | 18 | public string Name 19 | { 20 | get 21 | { 22 | if (!string.IsNullOrEmpty(FullName)) 23 | { 24 | return System.IO.Path.GetFileName(FullName); 25 | } 26 | else 27 | { 28 | return null; 29 | } 30 | } 31 | } 32 | 33 | public FileSystemRights AccessRights 34 | { 35 | get 36 | { 37 | return (FileSystemRights)accessMask; 38 | } 39 | } 40 | 41 | private List accessAsString; 42 | public List AccessAsString { get { return accessAsString; } } 43 | 44 | public FileSystemEffectivePermissionEntry(IdentityReference2 identity, uint AccessMask, string FullName) 45 | { 46 | this.account = identity; 47 | this.accessMask = AccessMask; 48 | this.objectPath = FullName; 49 | this.accessAsString = new List(); 50 | 51 | if (accessMask == 0) 52 | { 53 | accessAsString.Add("None"); 54 | } 55 | else 56 | { 57 | string tempString = ((FileSystemRights)this.accessMask).ToString(); 58 | foreach (var s in tempString.Split(',')) 59 | { 60 | this.accessAsString.Add(s); 61 | } 62 | } 63 | } 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /Security2/FileSystem/FileSystemFlags.cs: -------------------------------------------------------------------------------- 1 | using System.Security.AccessControl; 2 | 3 | namespace Security2 4 | { 5 | public class FileSystemFlags 6 | { 7 | public InheritanceFlags InheritanceFlags { get; set; } 8 | public PropagationFlags PropagationFlags { get; set; } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Security2/FileSystem/FileSystemOwner.cs: -------------------------------------------------------------------------------- 1 | using Alphaleonis.Win32.Filesystem; 2 | using System.Security.AccessControl; 3 | using System.Security.Principal; 4 | 5 | namespace Security2 6 | { 7 | public class FileSystemOwner 8 | { 9 | private FileSystemInfo item; 10 | private IdentityReference2 owner; 11 | private FileSystemSecurity sd; 12 | 13 | public FileSystemInfo Item 14 | { 15 | get { return item; } 16 | } 17 | 18 | public IdentityReference2 Owner 19 | { 20 | get { return owner; } 21 | } 22 | 23 | public IdentityReference2 Account 24 | { 25 | get { return owner; } 26 | } 27 | 28 | public string FullName 29 | { 30 | get { return item.FullName; } 31 | } 32 | 33 | private FileSystemOwner(FileSystemInfo item, IdentityReference2 owner) 34 | { 35 | this.item = item; 36 | this.owner = owner; 37 | } 38 | 39 | public static FileSystemOwner GetOwner(FileSystemSecurity2 sd) 40 | { 41 | return new FileSystemOwner(sd.Item, sd.SecurityDescriptor.GetOwner(typeof(SecurityIdentifier))); 42 | } 43 | 44 | public static void SetOwner(FileSystemSecurity2 sd, IdentityReference2 account) 45 | { 46 | sd.SecurityDescriptor.SetOwner(account); 47 | } 48 | 49 | public static FileSystemOwner GetOwner(FileSystemInfo item) 50 | { 51 | return GetOwner(new FileSystemSecurity2(item, AccessControlSections.Owner)); 52 | } 53 | 54 | public static void SetOwner(FileSystemInfo item, IdentityReference2 account) 55 | { 56 | var sd = new FileSystemSecurity2(item, AccessControlSections.Owner); 57 | 58 | SetOwner(sd, account); 59 | 60 | sd.Write(); 61 | } 62 | 63 | public override string ToString() 64 | { 65 | return item.FullName; 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /Security2/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("Security2")] 9 | [assembly: AssemblyDescription("Wrapper for security and identity classes")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("Microsoft")] 12 | [assembly: AssemblyProduct("Security2")] 13 | [assembly: AssemblyCopyright("Copyright © Raimund Andree 2015")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("d89dc40a-9b43-4bce-972d-b995df8d2820")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("3.2.3.0")] 36 | [assembly: AssemblyFileVersion("3.2.3.0")] 37 | -------------------------------------------------------------------------------- /Security2/Win32/Enums.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Security2 4 | { 5 | enum SECURITY_INFORMATION 6 | { 7 | OWNER_SECURITY_INFORMATION = 1, 8 | GROUP_SECURITY_INFORMATION = 2, 9 | DACL_SECURITY_INFORMATION = 4, 10 | SACL_SECURITY_INFORMATION = 8, 11 | } 12 | 13 | internal enum AuthzRpcClientVersion : ushort // USHORT 14 | { 15 | V1 = 1 16 | } 17 | 18 | [Flags] 19 | internal enum AuthzResourceManagerFlags : uint 20 | { 21 | NO_AUDIT = 0x1, 22 | } 23 | 24 | [Flags] 25 | internal enum StdAccess : uint 26 | { 27 | None = 0x0, 28 | 29 | SYNCHRONIZE = 0x100000, 30 | STANDARD_RIGHTS_REQUIRED = 0xF0000, 31 | 32 | MAXIMUM_ALLOWED = 0x2000000, 33 | } 34 | 35 | [Flags] 36 | internal enum AuthzInitFlags : uint 37 | { 38 | Default = 0x0, 39 | SkipTokenGroups = 0x2, 40 | RequireS4ULogon = 0x4, 41 | ComputePrivileges = 0x8, 42 | } 43 | 44 | internal enum AuthzACFlags : uint // DWORD 45 | { 46 | None = 0, 47 | NoDeepCopySD 48 | } 49 | 50 | [Flags] 51 | internal enum SecurityInformationClass : uint 52 | { 53 | Owner = 0x00001, 54 | Group = 0x00002, 55 | Dacl = 0x00004, 56 | Sacl = 0x00008, 57 | Label = 0x00010, 58 | Attribute = 0x00020, 59 | Scope = 0x00040 60 | } 61 | 62 | internal enum ObjectType : uint 63 | { 64 | File = 1, 65 | } 66 | 67 | [Flags] 68 | internal enum FileAccess : uint 69 | { 70 | None = 0x0, 71 | ReadData = 0x1, 72 | WriteData = 0x2, 73 | AppendData = 0x4, 74 | ReadExAttrib = 0x8, 75 | WriteExAttrib = 0x10, 76 | Execute = 0x20, 77 | DeleteChild = 0x40, 78 | ReadAttrib = 0x80, 79 | WriteAttrib = 0x100, 80 | 81 | Delete = 0x10000, // DELETE, 82 | ReadPermissions = 0x20000, // READ_CONTROL 83 | ChangePermissions = 0x40000, // WRITE_DAC, 84 | TakeOwnership = 0x80000, // WRITE_OWNER, 85 | 86 | GenericRead = ReadPermissions 87 | | ReadData 88 | | ReadAttrib 89 | | ReadExAttrib 90 | | StdAccess.SYNCHRONIZE, 91 | 92 | GenericAll = (StdAccess.STANDARD_RIGHTS_REQUIRED | 0x1FF), 93 | 94 | CategoricalAll = uint.MaxValue 95 | } 96 | 97 | [Flags] 98 | internal enum FileShare : uint 99 | { 100 | None = 0x0, 101 | Read = 0x1, 102 | Write = 0x2, 103 | Delete = 0x4 104 | } 105 | 106 | internal enum FileMode : uint 107 | { 108 | OpenExisting = 3, 109 | } 110 | 111 | [Flags] 112 | internal enum FileFlagAttrib : uint 113 | { 114 | BackupSemantics = 0x02000000, 115 | } 116 | } 117 | -------------------------------------------------------------------------------- /Security2/Win32/Errors.cs: -------------------------------------------------------------------------------- 1 | // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF 2 | // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO 3 | // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A 4 | // PARTICULAR PURPOSE. 5 | // 6 | // Copyright (c) Microsoft Corporation. All rights reserved 7 | 8 | using System; 9 | using System.Runtime.InteropServices; 10 | 11 | namespace Security2 12 | { 13 | static internal class Win32Error 14 | { 15 | // Note - the error codes here should all match the definitions in winerror.h. 16 | 17 | /// 18 | /// Equal to ERROR_SUCCESS (The operation completed successfully). 19 | /// 20 | public const int NO_ERROR = 0; 21 | 22 | /// 23 | /// Error code indicating: The operation completed successfully. 24 | /// 25 | public const int ERROR_SUCCESS = 0; 26 | 27 | /// 28 | /// The system cannot find the file specified. 29 | /// 30 | public const int ERROR_FILE_NOT_FOUND = 2; 31 | 32 | /// 33 | /// Error code indicating: Access is denied. 34 | /// 35 | public const int ERROR_ACCESS_DENIED = 5; 36 | 37 | /// 38 | /// Error code indicating: Not enough storage is available to process this command 39 | /// 40 | public const int ERROR_NOT_ENOUGH_MEMORY = 8; 41 | /// 42 | /// The data area passed to a system call is too small. 43 | /// 44 | public const int ERROR_INSUFFICIENT_BUFFER = 122; 45 | 46 | /// 47 | /// The filename or extension is too long. 48 | /// 49 | public const int ERROR_FILENAME_EXCED_RANGE = 206; 50 | 51 | /// 52 | /// More data is available. 53 | /// 54 | public const int ERROR_MORE_DATA = 234; 55 | 56 | /// 57 | /// An attempt was made to reference a token that does not exist. 58 | /// 59 | public const int ERROR_NO_TOKEN = 1008; 60 | 61 | /// 62 | /// The specified device name is invalid. 63 | /// 64 | public const int ERROR_BAD_DEVICE = 1200; 65 | 66 | /// 67 | /// Not all privileges or groups referenced are assigned to the caller. 68 | /// 69 | public const int ERROR_NOT_ALL_ASSIGNED = 1300; 70 | 71 | /// 72 | /// A specified privilege does not exist. 73 | /// 74 | public const int ERROR_NO_SUCH_PRIVILEGE = 1313; 75 | 76 | /// 77 | /// Cannot open an anonymous level security token. 78 | /// 79 | public const int ERROR_CANT_OPEN_ANONYMOUS = 1347; 80 | 81 | /// 82 | /// The RPC server is unavailable. 83 | /// 84 | public const int RPC_S_SERVER_UNAVAILABLE = 1722; 85 | 86 | /// 87 | /// There are no more endpoints available from the endpoint mapper. 88 | /// 89 | public const int EPT_S_NOT_REGISTERED = 1753; 90 | 91 | /// 92 | /// This network connection does not exist. 93 | /// 94 | public const int ERROR_NOT_CONNECTED = 2250; 95 | } 96 | } -------------------------------------------------------------------------------- /Security2/Win32/Structs.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | 4 | namespace Security2 5 | { 6 | internal partial class Win32 7 | { 8 | [StructLayout(LayoutKind.Sequential)] 9 | struct PINHERITED_FROM 10 | { 11 | public Int32 GenerationGap; 12 | [MarshalAs(UnmanagedType.LPTStr)] 13 | public string AncestorName; 14 | } 15 | 16 | [StructLayout(LayoutKind.Sequential)] 17 | struct GENERIC_MAPPING 18 | { 19 | public uint GenericRead; 20 | public uint GenericWrite; 21 | public uint GenericExecute; 22 | public uint GenericAll; 23 | } 24 | 25 | [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] 26 | struct AUTHZ_RPC_INIT_INFO_CLIENT 27 | { 28 | public AuthzRpcClientVersion version; 29 | public string objectUuid; 30 | public string protocol; 31 | public string server; 32 | public string endPoint; 33 | public string options; 34 | public string serverSpn; 35 | } 36 | 37 | [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] 38 | public struct LUID 39 | { 40 | public uint LowPart; 41 | public uint HighPart; 42 | 43 | public static LUID NullLuid 44 | { 45 | get 46 | { 47 | LUID Empty; 48 | Empty.LowPart = 0; 49 | Empty.HighPart = 0; 50 | 51 | return Empty; 52 | } 53 | } 54 | } 55 | 56 | #region authz 57 | [StructLayout(LayoutKind.Sequential)] 58 | internal struct AUTHZ_ACCESS_REQUEST 59 | { 60 | public StdAccess DesiredAccess; 61 | public byte[] PrincipalSelfSid; 62 | public IntPtr ObjectTypeList; 63 | public int ObjectTypeListLength; 64 | public IntPtr OptionalArguments; 65 | } 66 | 67 | [StructLayout(LayoutKind.Sequential)] 68 | internal struct AUTHZ_ACCESS_REPLY 69 | { 70 | public int ResultListLength; 71 | public IntPtr GrantedAccessMask; 72 | public IntPtr SaclEvaluationResults; 73 | public IntPtr Error; 74 | } 75 | 76 | internal enum AuthzACFlags : uint // DWORD 77 | { 78 | None = 0, 79 | NoDeepCopySD 80 | } 81 | #endregion 82 | } 83 | } -------------------------------------------------------------------------------- /Security2/Win32/Win32Functions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | 4 | namespace Security2 5 | { 6 | internal partial class Win32 7 | { 8 | const string ADVAPI32_DLL = "advapi32.dll"; 9 | const string KERNEL32_DLL = "kernel32.dll"; 10 | 11 | [DllImport(Win32.ADVAPI32_DLL, EntryPoint = "GetInheritanceSourceW", CharSet = CharSet.Unicode)] 12 | static extern UInt32 GetInheritanceSource( 13 | [MarshalAs(UnmanagedType.LPTStr)] string pObjectName, 14 | System.Security.AccessControl.ResourceType ObjectType, 15 | SECURITY_INFORMATION SecurityInfo, 16 | [MarshalAs(UnmanagedType.Bool)]bool Container, 17 | IntPtr pObjectClassGuids, 18 | UInt32 GuidCount, 19 | byte[] pAcl, 20 | IntPtr pfnArray, 21 | ref GENERIC_MAPPING pGenericMapping, 22 | IntPtr pInheritArray 23 | ); 24 | 25 | [DllImport(Win32.ADVAPI32_DLL, EntryPoint = "FreeInheritedFromArray", CharSet = CharSet.Unicode)] 26 | static extern UInt32 FreeInheritedFromArray( 27 | IntPtr pInheritArray, 28 | UInt16 AceCnt, 29 | IntPtr pfnArray 30 | ); 31 | } 32 | } -------------------------------------------------------------------------------- /Security2/Win32/Win32Lib.cs: -------------------------------------------------------------------------------- 1 | using Alphaleonis.Win32.Filesystem; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Runtime.InteropServices; 6 | using System.Security.AccessControl; 7 | using System.Text; 8 | 9 | namespace Security2 10 | { 11 | internal partial class Win32 12 | { 13 | public static List GetInheritedFrom(string path, ObjectSecurity sd, bool isContainer) 14 | { 15 | var inheritedFrom = new List(); 16 | path = Path.GetLongPath(path); 17 | 18 | uint returnValue = 0; 19 | GENERIC_MAPPING genericMap = new GENERIC_MAPPING(); 20 | genericMap.GenericRead = (uint)MappedGenericRights.FILE_GENERIC_READ; 21 | genericMap.GenericWrite = (uint)MappedGenericRights.FILE_GENERIC_WRITE; 22 | genericMap.GenericExecute = (uint)MappedGenericRights.FILE_GENERIC_EXECUTE; 23 | genericMap.GenericAll = (uint)MappedGenericRights.FILE_GENERIC_ALL; 24 | 25 | var sdBytes = sd.GetSecurityDescriptorBinaryForm(); 26 | var commonSd = new CommonSecurityDescriptor(isContainer, false, sdBytes, 0); 27 | 28 | var aclBytes = new byte[commonSd.DiscretionaryAcl.BinaryLength]; 29 | commonSd.DiscretionaryAcl.GetBinaryForm(aclBytes, 0); 30 | 31 | var pInheritInfo = Marshal.AllocHGlobal(commonSd.DiscretionaryAcl.Count * Marshal.SizeOf(typeof(PINHERITED_FROM))); 32 | 33 | returnValue = GetInheritanceSource( 34 | path, 35 | ResourceType.FileObject, 36 | SECURITY_INFORMATION.DACL_SECURITY_INFORMATION, 37 | isContainer, 38 | IntPtr.Zero, 39 | 0, 40 | aclBytes, 41 | IntPtr.Zero, 42 | ref genericMap, 43 | pInheritInfo 44 | ); 45 | 46 | if (returnValue != 0) 47 | { 48 | throw new System.ComponentModel.Win32Exception((int)returnValue); 49 | } 50 | 51 | for (int i = 0; i < commonSd.DiscretionaryAcl.Count; i++) 52 | { 53 | var inheritInfo = pInheritInfo.ElementAt(i); 54 | 55 | inheritedFrom.Add( 56 | !string.IsNullOrEmpty(inheritInfo.AncestorName) && inheritInfo.AncestorName.StartsWith(@"\\?\") ? inheritInfo.AncestorName.Substring(4) : inheritInfo.AncestorName 57 | ); 58 | } 59 | 60 | FreeInheritedFromArray(pInheritInfo, (ushort)commonSd.DiscretionaryAcl.Count, IntPtr.Zero); 61 | Marshal.FreeHGlobal(pInheritInfo); 62 | 63 | return inheritedFrom; 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /Security2/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /TestClient/Program.cs: -------------------------------------------------------------------------------- 1 | using Alphaleonis.Win32.Filesystem; 2 | using NTFSSecurity; 3 | using Security2; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Linq; 7 | using System.Management.Automation; 8 | using System.Management.Automation.Runspaces; 9 | using System.Security.AccessControl; 10 | using System.Security.Principal; 11 | 12 | namespace TestClient 13 | { 14 | class Program 15 | { 16 | static void Main(string[] args) 17 | { 18 | var item1 = new FileInfo("D:\\file1.txt"); 19 | var item2 = new DirectoryInfo("D:\\test3"); 20 | var account1 = new List() { (IdentityReference2)@"raandree1\randr_000" }; 21 | 22 | FileSystemAccessRule2.AddFileSystemAccessRule(item1, account1, FileSystemRights2.FullControl, AccessControlType.Allow, InheritanceFlags.ContainerInherit, PropagationFlags.None); 23 | 24 | return; 25 | var path = @"C:\Windows"; 26 | var account = @"raandree1\randr_000"; 27 | var server = "localhost"; 28 | 29 | var sd = Directory.GetAccessControl(path, AccessControlSections.Access); 30 | var id = new IdentityReference2(account); 31 | EffectiveAccess.GetEffectiveAccess(new FileInfo(path), id, "localhost"); 32 | 33 | var result1 = InvokeCommand("gi2 c:\\windows"); 34 | 35 | var result2 = InvokeCommand(@"gi -Path D:\SingleMachine\ | Get-EffectiveAccess") 36 | .Select(ace => ace.ImmediateBaseObject) 37 | .Cast().ToList(); 38 | 39 | foreach (var ace in result2) 40 | { 41 | Console.WriteLine(string.Format("{0};{1}", ace.Account, ace.IsInherited)); 42 | } 43 | 44 | Console.ReadKey(); 45 | } 46 | 47 | public static List InvokeCommand(string script) 48 | { 49 | var runspace = RunspaceFactory.CreateRunspace(); 50 | runspace.Open(); 51 | var powershell = PowerShell.Create(); 52 | powershell.Runspace = runspace; 53 | 54 | powershell.Commands.AddScript(script); 55 | var result = powershell.Invoke(); 56 | 57 | powershell.Dispose(); 58 | runspace.Close(); 59 | 60 | return result.ToList(); 61 | } 62 | 63 | public static List InvokeCommand(string command, Dictionary parameters) 64 | { 65 | var runspace = RunspaceFactory.CreateRunspace(); 66 | runspace.Open(); 67 | var powershell = PowerShell.Create(); 68 | powershell.Runspace = runspace; 69 | 70 | var cmd = new Command(command); 71 | foreach (var parameter in parameters) 72 | { 73 | cmd.Parameters.Add(parameter.Key, parameter.Value); 74 | } 75 | 76 | powershell.Commands.AddCommand(cmd); 77 | var result = powershell.Invoke(); 78 | 79 | powershell.Dispose(); 80 | runspace.Close(); 81 | 82 | return result.ToList(); 83 | } 84 | } 85 | } -------------------------------------------------------------------------------- /TestClient/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("TestClient")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("Microsoft")] 12 | [assembly: AssemblyProduct("TestClient")] 13 | [assembly: AssemblyCopyright("Copyright © Microsoft 2012")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("300b183b-855e-43f5-bc5c-4bcfb436cdf2")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /TestClient/app.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /TestClient/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /appveyor.yml: -------------------------------------------------------------------------------- 1 | install: 2 | - ps: | 3 | Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force 4 | Install-Module platyPS -Force 5 | Install-Module MarkdownLinkCheck -Force 6 | Install-Module NTFSSecurity -Force 7 | Import-Module platyPS 8 | Import-Module MarkdownLinkCheck 9 | 10 | init: 11 | - ps: git config --global core.autocrlf true 12 | 13 | build_script: 14 | - ps: Import-Module -Force NTFSSecurity 15 | 16 | test_script: 17 | - ps: | 18 | $ErrorActionPreference = 'Stop' 19 | 20 | # 01. Test that documentation is up-to-date 21 | Update-MarkdownHelp -Path ./Docs/Cmdlets 22 | $Diff = git diff 23 | if ($Diff) { 24 | throw "Help is not up-to-date, run Update-MarkdownHelp: $diff" 25 | } 26 | 27 | # 02. Verify hyperlinks 28 | $BrokenLinks = Get-MarkdownLink -Path .\Docs\ -BrokenOnly 29 | if ($brokenLinks) { 30 | throw "Found broken hyperlinks $brokenLinks" 31 | } -------------------------------------------------------------------------------- /mkdocs.yml: -------------------------------------------------------------------------------- 1 | copyright: The NTFSSecurity module is licensed under the MIT license 2 | repo_url: https://github.com/raandree/NTFSSecurity 3 | nav: 4 | - Home: ./index.md 5 | - Concepts: ./Concepts.md 6 | - Cmdlets: 7 | - Add-NTFSAccess: Cmdlets/Add-NTFSAccess.md 8 | - Add-NTFSAudit: Cmdlets/Add-NTFSAudit.md 9 | - Clear-NTFSAccess: Cmdlets/Clear-NTFSAccess.md 10 | - Clear-NTFSAudit: Cmdlets/Clear-NTFSAudit.md 11 | - Copy-Item2: Cmdlets/Copy-Item2.md 12 | - Disable-NTFSAccessInheritance: Cmdlets/Disable-NTFSAccessInheritance.md 13 | - Disable-NTFSAuditInheritance: Cmdlets/Disable-NTFSAuditInheritance.md 14 | - Disable-Privileges: Cmdlets/Disable-Privileges.md 15 | - Enable-NTFSAccessInheritance: Cmdlets/Enable-NTFSAccessInheritance.md 16 | - Enable-NTFSAuditInheritance: Cmdlets/Enable-NTFSAuditInheritance.md 17 | - Enable-Privileges: Cmdlets/Enable-Privileges.md 18 | - Get-ChildItem2: Cmdlets/Get-ChildItem2.md 19 | - Get-DiskSpace: Cmdlets/Get-DiskSpace.md 20 | - Get-FileHash2: Cmdlets/Get-FileHash2.md 21 | - Get-Item2: Cmdlets/Get-Item2.md 22 | - Get-NTFSAccess: Cmdlets/Get-NTFSAccess.md 23 | - Get-NTFSAudit: Cmdlets/Get-NTFSAudit.md 24 | - Get-NTFSEffectiveAccess: Cmdlets/Get-NTFSEffectiveAccess.md 25 | - Get-NTFSHardLink: Cmdlets/Get-NTFSHardLink.md 26 | - Get-NTFSInheritance: Cmdlets/Get-NTFSInheritance.md 27 | - Get-NTFSOrphanedAccess: Cmdlets/Get-NTFSOrphanedAccess.md 28 | - Get-NTFSOrphanedAudit: Cmdlets/Get-NTFSOrphanedAudit.md 29 | - Get-NTFSOwner: Cmdlets/Get-NTFSOwner.md 30 | - Get-NTFSSecurityDescriptor: Cmdlets/Get-NTFSSecurityDescriptor.md 31 | - Get-NTFSSimpleAccess: Cmdlets/Get-NTFSSimpleAccess.md 32 | - Get-Privileges: Cmdlets/Get-Privileges.md 33 | - Move-Item2: Cmdlets/Move-Item2.md 34 | - New-NTFSHardLink: Cmdlets/New-NTFSHardLink.md 35 | - New-NTFSSymbolicLink: Cmdlets/New-NTFSSymbolicLink.md 36 | - Remove-Item2: Cmdlets/Remove-Item2.md 37 | - Remove-NTFSAccess: Cmdlets/Remove-NTFSAccess.md 38 | - Remove-NTFSAudit: Cmdlets/Remove-NTFSAudit.md 39 | - Set-NTFSInheritance: Cmdlets/Set-NTFSInheritance.md 40 | - Set-NTFSOwner: Cmdlets/Set-NTFSOwner.md 41 | - Set-NTFSSecurityDescriptor: Cmdlets/Set-NTFSSecurityDescriptor.md 42 | - Test-Path2: Cmdlets/Test-Path2.md 43 | - Contributing: 44 | - Getting Started: Contributing/01-Getting-Started.md 45 | - Writing: Contributing/02-Writing.md 46 | - Style Guide: Contributing/03-Style-Guide.md 47 | - Markdown Specifics: Contributing:04-Markdown-Specifics.md 48 | site_name: NTFSSecurity 49 | theme: readthedocs 50 | site_author: Raimund Andrée, James Smith 51 | docs_dir: ./Docs --------------------------------------------------------------------------------