Browse Source

fix: declare and write the right output types

Defect 22:

- [OutputType]: Test-Path2 writes System.Boolean, not file objects;
  Get-FileHash2 writes the file object with Hash and Algorithm, not access
  rules; Add-NTFSAudit and Remove-NTFSAudit write audit entries since
  defect 6; Copy-Item2, Move-Item2, Remove-Item2, and the five inheritance
  cmdlets with -PassThru declared no type.
- Enable-Privileges and Disable-Privileges with -PassThru wrote the
  privileges as one collection; they now enumerate it.
- New-NTFSSymbolicLink -PassThru returned a FileInfo for a link to a
  folder; it now returns a DirectoryInfo.

The OUTPUTS sections of the pages name the same types.

Tests/OutputTypes.Tests.ps1 (new): 15 tests; Disable-Privileges and the
symbolic link need privileges and run in CI.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: AI Assistant <ai@example.com>
pull/103/head
Raimund Andree 7 days ago
parent
commit
f2c551e17a
  1. 8
      CHANGELOG.md
  2. 8
      Docs/Cmdlets/Copy-Item2.md
  3. 2
      Docs/Cmdlets/Disable-NTFSAccessInheritance.md
  4. 2
      Docs/Cmdlets/Disable-NTFSAuditInheritance.md
  5. 2
      Docs/Cmdlets/Disable-Privileges.md
  6. 2
      Docs/Cmdlets/Enable-NTFSAccessInheritance.md
  7. 2
      Docs/Cmdlets/Enable-NTFSAuditInheritance.md
  8. 2
      Docs/Cmdlets/Enable-Privileges.md
  9. 4
      Docs/Cmdlets/Get-FileHash2.md
  10. 8
      Docs/Cmdlets/Move-Item2.md
  11. 4
      Docs/Cmdlets/New-NTFSSymbolicLink.md
  12. 8
      Docs/Cmdlets/Remove-Item2.md
  13. 2
      Docs/Cmdlets/Set-NTFSInheritance.md
  14. 8
      Docs/Cmdlets/Test-Path2.md
  15. 2
      NTFSSecurity/AuditCmdlets/AddAudit.cs
  16. 2
      NTFSSecurity/AuditCmdlets/RemoveAudit.cs
  17. 1
      NTFSSecurity/InheritanceCmdlets/DisableAccessInheritance.cs
  18. 1
      NTFSSecurity/InheritanceCmdlets/DisableAuditInheritance.cs
  19. 1
      NTFSSecurity/InheritanceCmdlets/EnableAccessInheritance.cs
  20. 1
      NTFSSecurity/InheritanceCmdlets/EnableAuditInheritance.cs
  21. 1
      NTFSSecurity/InheritanceCmdlets/SetInheritance.cs
  22. 1
      NTFSSecurity/ItemCmdlets/CopyItem2.cs
  23. 1
      NTFSSecurity/ItemCmdlets/MoveItem2.cs
  24. 1
      NTFSSecurity/ItemCmdlets/RemoveItem2.cs
  25. 5
      NTFSSecurity/LinkCmdlets/NewSymbolicLink.cs
  26. 2
      NTFSSecurity/MiscCmdlets/GetFileHash2.cs
  27. 4
      NTFSSecurity/OtherCmdlets.cs
  28. 2
      NTFSSecurity/PathCmdlets/TestPath2.cs
  29. 70
      NTFSSecurity/en-US/NTFSSecurity.dll-Help.xml
  30. 87
      Tests/OutputTypes.Tests.ps1

8
CHANGELOG.md

@ -134,5 +134,13 @@ The format is based on
- Fix the cmdlets that take ownership of an item to repeat an operation that
was denied: when the second attempt failed as well, the account that ran
the cmdlet stayed the owner of the item; now the previous owner is restored
- Fix `-PassThru` of `Enable-Privileges` and `Disable-Privileges`, which
wrote the privileges as one collection instead of one object per
privilege, and of `New-NTFSSymbolicLink`, which returned a file object for
a link to a folder
- Declare the output types of `Test-Path2`, `Get-FileHash2`,
`Add-NTFSAudit`, `Remove-NTFSAudit`, `Copy-Item2`, `Move-Item2`,
`Remove-Item2`, and the inheritance cmdlets correctly, so that
`Get-Command` and tab completion report the objects they write
[Unreleased]: https://github.com/raandree/NTFSSecurity/compare/4.2.6...HEAD

8
Docs/Cmdlets/Copy-Item2.md

@ -176,9 +176,13 @@ You can pipe an object that has a `Destination` property to supply the target of
## OUTPUTS
### System.Object
### Alphaleonis.Win32.Filesystem.FileInfo
By default this cmdlet returns nothing. With `-PassThru $true` it returns an `Alphaleonis.Win32.Filesystem.FileInfo` or `Alphaleonis.Win32.Filesystem.DirectoryInfo` object for each item that it copied.
By default this cmdlet returns nothing. With `-PassThru $true` it returns a file object for each file that it copied.
### Alphaleonis.Win32.Filesystem.DirectoryInfo
With `-PassThru $true` the cmdlet returns a folder object for each folder that it copied.
## NOTES

2
Docs/Cmdlets/Disable-NTFSAccessInheritance.md

@ -156,7 +156,7 @@ You can pipe the security descriptors that `Get-NTFSSecurityDescriptor` returns
## OUTPUTS
### System.Object
### Security2.FileSystemInheritanceInfo
By default this cmdlet returns no output. With `-PassThru` it writes one `Security2.FileSystemInheritanceInfo` object per item, which reports the `AccessInheritanceEnabled` and `AuditInheritanceEnabled` state after the change.

2
Docs/Cmdlets/Disable-NTFSAuditInheritance.md

@ -156,7 +156,7 @@ You can pipe the security descriptors that `Get-NTFSSecurityDescriptor` returns
## OUTPUTS
### System.Object
### Security2.FileSystemInheritanceInfo
By default this cmdlet returns no output. With `-PassThru` it writes one `Security2.FileSystemInheritanceInfo` object per item, which reports the `AccessInheritanceEnabled` and `AuditInheritanceEnabled` state after the change.

2
Docs/Cmdlets/Disable-Privileges.md

@ -93,7 +93,7 @@ This cmdlet does not accept pipeline input.
### ProcessPrivileges.PrivilegeAndAttributes
With `-PassThru`, the cmdlet writes the privilege collection of the current process. The pipeline enumerates it into one `ProcessPrivileges.PrivilegeAndAttributes` object per privilege, each with a `Privilege`, a `PrivilegeAttributes`, and a `PrivilegeState` property. Without `-PassThru`, the cmdlet writes nothing.
With `-PassThru`, the cmdlet writes one `ProcessPrivileges.PrivilegeAndAttributes` object per privilege of the current process, each with a `Privilege`, a `PrivilegeAttributes`, and a `PrivilegeState` property. Without `-PassThru`, the cmdlet writes nothing. Before 5.0.0, it wrote the privileges as one collection.
## NOTES

2
Docs/Cmdlets/Enable-NTFSAccessInheritance.md

@ -155,7 +155,7 @@ You can pipe the security descriptors that `Get-NTFSSecurityDescriptor` returns
## OUTPUTS
### System.Object
### Security2.FileSystemInheritanceInfo
By default this cmdlet returns no output. With `-PassThru` it writes one `Security2.FileSystemInheritanceInfo` object per item, which reports the `AccessInheritanceEnabled` and `AuditInheritanceEnabled` state after the change.

2
Docs/Cmdlets/Enable-NTFSAuditInheritance.md

@ -155,7 +155,7 @@ You can pipe the security descriptors that `Get-NTFSSecurityDescriptor` returns
## OUTPUTS
### System.Object
### Security2.FileSystemInheritanceInfo
By default this cmdlet returns no output. With `-PassThru` it writes one `Security2.FileSystemInheritanceInfo` object per item, which reports the `AccessInheritanceEnabled` and `AuditInheritanceEnabled` state after the change.

2
Docs/Cmdlets/Enable-Privileges.md

@ -95,7 +95,7 @@ This cmdlet does not accept pipeline input.
### ProcessPrivileges.PrivilegeAndAttributes
With `-PassThru`, the cmdlet writes the privilege collection of the current process. The pipeline enumerates it into one `ProcessPrivileges.PrivilegeAndAttributes` object per privilege, each with a `Privilege`, a `PrivilegeAttributes`, and a `PrivilegeState` property. Without `-PassThru`, the cmdlet writes nothing.
With `-PassThru`, the cmdlet writes one `ProcessPrivileges.PrivilegeAndAttributes` object per privilege of the current process, each with a `Privilege`, a `PrivilegeAttributes`, and a `PrivilegeState` property. Without `-PassThru`, the cmdlet writes nothing. Before 5.0.0, it wrote the privileges as one collection.
## NOTES

4
Docs/Cmdlets/Get-FileHash2.md

@ -111,9 +111,9 @@ You can supply the `-Algorithm` value through a pipeline object that has an `Alg
## OUTPUTS
### Security2.FileSystemAccessRule2
### Alphaleonis.Win32.Filesystem.FileInfo
The cmdlet does not return access rules. For every hashed file it writes the file object of that file, decorated with the type name `Alphaleonis.Win32.Filesystem.FileInfo+Hash` and extended with the `Hash` and `Algorithm` note properties, so all regular file properties such as `FullName`, `Name`, and `Length` remain available.
For every hashed file, the cmdlet writes the file object of that file, decorated with the type name `Alphaleonis.Win32.Filesystem.FileInfo+Hash` and extended with the `Hash` and `Algorithm` note properties, so all regular file properties such as `FullName`, `Name`, and `Length` remain available.
## NOTES

8
Docs/Cmdlets/Move-Item2.md

@ -176,9 +176,13 @@ You can pipe an object that has a `Destination` property to supply the target of
## OUTPUTS
### System.Object
### Alphaleonis.Win32.Filesystem.FileInfo
By default this cmdlet returns nothing. With `-PassThru $true` it returns an `Alphaleonis.Win32.Filesystem.FileInfo` or `Alphaleonis.Win32.Filesystem.DirectoryInfo` object for each item that it moved, pointing at the new location.
By default this cmdlet returns nothing. With `-PassThru $true` it returns a file object for each file that it moved, pointing at the new location.
### Alphaleonis.Win32.Filesystem.DirectoryInfo
With `-PassThru $true` the cmdlet returns a folder object for each folder that it moved, pointing at the new location.
## NOTES

4
Docs/Cmdlets/New-NTFSSymbolicLink.md

@ -124,11 +124,11 @@ You can pass the path of the new link and the path of the target as strings.
### Alphaleonis.Win32.Filesystem.FileInfo
With `-PassThru`, the cmdlet writes a file object for the new link. The cmdlet writes that object type for a link to a folder as well. Without `-PassThru`, the cmdlet writes nothing.
With `-PassThru`, the cmdlet writes a file object for a new link to a file. Without `-PassThru`, the cmdlet writes nothing.
### Alphaleonis.Win32.Filesystem.DirectoryInfo
The cmdlet does not write folder objects. A directory symbolic link is also returned as a file object.
With `-PassThru`, the cmdlet writes a folder object for a new link to a folder. Before 5.0.0, it wrote a file object for those links as well.
## NOTES

8
Docs/Cmdlets/Remove-Item2.md

@ -169,9 +169,13 @@ You can pipe one or more paths to this cmdlet, either as strings or as objects t
## OUTPUTS
### System.Object
### Alphaleonis.Win32.Filesystem.FileInfo
By default this cmdlet returns nothing. With `-PassThru` it returns an `Alphaleonis.Win32.Filesystem.FileInfo` or `Alphaleonis.Win32.Filesystem.DirectoryInfo` object for each item that it deleted.
By default this cmdlet returns nothing. With `-PassThru` it returns a file object for each file that it deleted.
### Alphaleonis.Win32.Filesystem.DirectoryInfo
With `-PassThru` the cmdlet returns a folder object for each folder that it deleted.
## NOTES

2
Docs/Cmdlets/Set-NTFSInheritance.md

@ -178,7 +178,7 @@ You can supply `-AccessInheritanceEnabled` and `-AuditInheritanceEnabled` throug
## OUTPUTS
### System.Object
### Security2.FileSystemInheritanceInfo
By default this cmdlet returns no output. With `-PassThru` it writes one `Security2.FileSystemInheritanceInfo` object per item, which reports the `AccessInheritanceEnabled` and `AuditInheritanceEnabled` state after the change.

8
Docs/Cmdlets/Test-Path2.md

@ -109,13 +109,9 @@ You can supply the `-PathType` value through a pipeline object that has a `PathT
## OUTPUTS
### Alphaleonis.Win32.Filesystem.FileInfo
### System.Boolean
`Test-Path2` does not write file objects. For each path it writes a single `System.Boolean` value that is `$true` when the item exists and matches `-PathType`, and `$false` otherwise.
### Alphaleonis.Win32.Filesystem.DirectoryInfo
`Test-Path2` does not write folder objects either. A folder is reported through the same `System.Boolean` result as a file.
For each path, the cmdlet writes `$true` when the item exists and matches `-PathType`, and `$false` otherwise.
## NOTES

2
NTFSSecurity/AuditCmdlets/AddAudit.cs

@ -8,7 +8,7 @@ using System.Security.AccessControl;
namespace NTFSSecurity
{
[Cmdlet(VerbsCommon.Add, "NTFSAudit", DefaultParameterSetName = "PathComplex")]
[OutputType(typeof(FileSystemAccessRule2))]
[OutputType(typeof(FileSystemAuditRule2))]
public class AddAudit : BaseCmdletWithPrivControl
{
private IdentityReference2[] account;

2
NTFSSecurity/AuditCmdlets/RemoveAudit.cs

@ -8,7 +8,7 @@ using System.Security.AccessControl;
namespace NTFSSecurity
{
[Cmdlet(VerbsCommon.Remove, "NTFSAudit", DefaultParameterSetName = "PathComplex")]
[OutputType(typeof(FileSystemAccessRule2))]
[OutputType(typeof(FileSystemAuditRule2))]
public class RemoveAudit : BaseCmdletWithPrivControl
{
private IdentityReference2[] account;

1
NTFSSecurity/InheritanceCmdlets/DisableAccessInheritance.cs

@ -6,6 +6,7 @@ using System.Management.Automation;
namespace NTFSSecurity
{
[Cmdlet(VerbsLifecycle.Disable, "NTFSAccessInheritance", DefaultParameterSetName = "Path")]
[OutputType(typeof(FileSystemInheritanceInfo))]
public class DisableAccessInheritance : BaseCmdletWithPrivControl
{
private bool removeInheritedAccessRules;

1
NTFSSecurity/InheritanceCmdlets/DisableAuditInheritance.cs

@ -7,6 +7,7 @@ namespace NTFSSecurity
{
[Cmdlet(VerbsLifecycle.Disable, "NTFSAuditInheritance", DefaultParameterSetName = "Path")]
[OutputType(typeof(FileSystemInheritanceInfo))]
public class DisableAuditInheritance : BaseCmdletWithPrivControl
{
private bool removeInheritedAccessRules;

1
NTFSSecurity/InheritanceCmdlets/EnableAccessInheritance.cs

@ -6,6 +6,7 @@ using System.Management.Automation;
namespace NTFSSecurity
{
[Cmdlet(VerbsLifecycle.Enable, "NTFSAccessInheritance", DefaultParameterSetName = "Path")]
[OutputType(typeof(FileSystemInheritanceInfo))]
public class EnableAccessInheritance : BaseCmdletWithPrivControl
{
private bool removeExplicitAccessRules;

1
NTFSSecurity/InheritanceCmdlets/EnableAuditInheritance.cs

@ -6,6 +6,7 @@ using System.Management.Automation;
namespace NTFSSecurity
{
[Cmdlet(VerbsLifecycle.Enable, "NTFSAuditInheritance", DefaultParameterSetName = "Path")]
[OutputType(typeof(FileSystemInheritanceInfo))]
public class EnableAuditInheritance : BaseCmdletWithPrivControl
{
private bool removeExplicitAccessRules;

1
NTFSSecurity/InheritanceCmdlets/SetInheritance.cs

@ -6,6 +6,7 @@ using System.Management.Automation;
namespace NTFSSecurity
{
[Cmdlet(VerbsCommon.Set, "NTFSInheritance", DefaultParameterSetName = "Path")]
[OutputType(typeof(FileSystemInheritanceInfo))]
public class SetInheritance : BaseCmdletWithPrivControl
{
private bool? accessInheritanceEnabled;

1
NTFSSecurity/ItemCmdlets/CopyItem2.cs

@ -5,6 +5,7 @@ using System.Management.Automation;
namespace NTFSSecurity
{
[Cmdlet(VerbsCommon.Copy, "Item2", SupportsShouldProcess = true)]
[OutputType(typeof(FileInfo), typeof(DirectoryInfo))]
public class CopyItem2 : BaseCmdlet
{
private string destination;

1
NTFSSecurity/ItemCmdlets/MoveItem2.cs

@ -5,6 +5,7 @@ using System.Management.Automation;
namespace NTFSSecurity
{
[Cmdlet(VerbsCommon.Move, "Item2", SupportsShouldProcess = true)]
[OutputType(typeof(FileInfo), typeof(DirectoryInfo))]
public class MoveItem2 : BaseCmdlet
{
private string destination;

1
NTFSSecurity/ItemCmdlets/RemoveItem2.cs

@ -5,6 +5,7 @@ using System.Management.Automation;
namespace NTFSSecurity
{
[Cmdlet(VerbsCommon.Remove, "Item2", SupportsShouldProcess = true)]
[OutputType(typeof(FileInfo), typeof(DirectoryInfo))]
public class RemoveItem2 : BaseCmdlet
{
private SwitchParameter force;

5
NTFSSecurity/LinkCmdlets/NewSymbolicLink.cs

@ -70,7 +70,10 @@ namespace NTFSSecurity
if (passThru)
{
WriteObject(new FileInfo(path));
if (targetItem is FileInfo)
WriteObject(new FileInfo(path));
else
WriteObject(new DirectoryInfo(path));
}
}
catch (System.IO.FileNotFoundException ex)

2
NTFSSecurity/MiscCmdlets/GetFileHash2.cs

@ -7,7 +7,7 @@ using Security2.FileSystem.FileInfo;
namespace NTFSSecurity
{
[Cmdlet(VerbsCommon.Get, "FileHash2")]
[OutputType(typeof(FileSystemAccessRule2))]
[OutputType(typeof(FileInfo))]
public class GetFileHash2 : BaseCmdlet
{
private HashAlgorithms algorithm = HashAlgorithms.SHA256;

4
NTFSSecurity/OtherCmdlets.cs

@ -54,7 +54,7 @@ namespace NTFSSecurity
if (passThru)
{
this.WriteObject(this.privControl.GetPrivileges());
this.WriteObject(this.privControl.GetPrivileges(), true);
}
}
@ -104,7 +104,7 @@ namespace NTFSSecurity
if (passThru)
{
this.WriteObject(this.privControl.GetPrivileges());
this.WriteObject(this.privControl.GetPrivileges(), true);
}
}

2
NTFSSecurity/PathCmdlets/TestPath2.cs

@ -5,7 +5,7 @@ using System.Management.Automation;
namespace NTFSSecurity
{
[Cmdlet(VerbsDiagnostic.Test, "Path2")]
[OutputType(typeof(FileInfo), typeof(DirectoryInfo))]
[OutputType(typeof(bool))]
public class TestPath2 : BaseCmdlet
{
private TestPathType pathType = TestPathType.Any;

70
NTFSSecurity/en-US/NTFSSecurity.dll-Help.xml

@ -2163,10 +2163,18 @@ PS C:\&gt; Set-NTFSSecurityDescriptor -SecurityDescriptor $sd</dev:code>
<command:returnValues>
<command:returnValue>
<dev:type>
<maml:name>System.Object</maml:name>
<maml:name>Alphaleonis.Win32.Filesystem.FileInfo</maml:name>
</dev:type>
<maml:description>
<maml:para>By default this cmdlet returns nothing. With `-PassThru $true` it returns a file object for each file that it copied.</maml:para>
</maml:description>
</command:returnValue>
<command:returnValue>
<dev:type>
<maml:name>Alphaleonis.Win32.Filesystem.DirectoryInfo</maml:name>
</dev:type>
<maml:description>
<maml:para>By default this cmdlet returns nothing. With `-PassThru $true` it returns an `Alphaleonis.Win32.Filesystem.FileInfo` or `Alphaleonis.Win32.Filesystem.DirectoryInfo` object for each item that it copied.</maml:para>
<maml:para>With `-PassThru $true` the cmdlet returns a folder object for each folder that it copied.</maml:para>
</maml:description>
</command:returnValue>
</command:returnValues>
@ -2400,7 +2408,7 @@ PS C:\&gt; Set-NTFSSecurityDescriptor -SecurityDescriptor $sd</dev:code>
<command:returnValues>
<command:returnValue>
<dev:type>
<maml:name>System.Object</maml:name>
<maml:name>Security2.FileSystemInheritanceInfo</maml:name>
</dev:type>
<maml:description>
<maml:para>By default this cmdlet returns no output. With `-PassThru` it writes one `Security2.FileSystemInheritanceInfo` object per item, which reports the `AccessInheritanceEnabled` and `AuditInheritanceEnabled` state after the change.</maml:para>
@ -2645,7 +2653,7 @@ PS C:\&gt; Set-NTFSSecurityDescriptor -SecurityDescriptor $sd</dev:code>
<command:returnValues>
<command:returnValue>
<dev:type>
<maml:name>System.Object</maml:name>
<maml:name>Security2.FileSystemInheritanceInfo</maml:name>
</dev:type>
<maml:description>
<maml:para>By default this cmdlet returns no output. With `-PassThru` it writes one `Security2.FileSystemInheritanceInfo` object per item, which reports the `AccessInheritanceEnabled` and `AuditInheritanceEnabled` state after the change.</maml:para>
@ -2785,7 +2793,7 @@ PS C:\&gt; Set-NTFSSecurityDescriptor -SecurityDescriptor $sd</dev:code>
<maml:name>ProcessPrivileges.PrivilegeAndAttributes</maml:name>
</dev:type>
<maml:description>
<maml:para>With `-PassThru`, the cmdlet writes the privilege collection of the current process. The pipeline enumerates it into one `ProcessPrivileges.PrivilegeAndAttributes` object per privilege, each with a `Privilege`, a `PrivilegeAttributes`, and a `PrivilegeState` property. Without `-PassThru`, the cmdlet writes nothing.</maml:para>
<maml:para>With `-PassThru`, the cmdlet writes one `ProcessPrivileges.PrivilegeAndAttributes` object per privilege of the current process, each with a `Privilege`, a `PrivilegeAttributes`, and a `PrivilegeState` property. Without `-PassThru`, the cmdlet writes nothing. Before 5.0.0, it wrote the privileges as one collection.</maml:para>
</maml:description>
</command:returnValue>
</command:returnValues>
@ -3017,7 +3025,7 @@ PS C:\&gt; Get-Privileges | Where-Object { $_.Privilege -in 'Backup', 'Restore',
<command:returnValues>
<command:returnValue>
<dev:type>
<maml:name>System.Object</maml:name>
<maml:name>Security2.FileSystemInheritanceInfo</maml:name>
</dev:type>
<maml:description>
<maml:para>By default this cmdlet returns no output. With `-PassThru` it writes one `Security2.FileSystemInheritanceInfo` object per item, which reports the `AccessInheritanceEnabled` and `AuditInheritanceEnabled` state after the change.</maml:para>
@ -3262,7 +3270,7 @@ PS C:\&gt; Set-NTFSSecurityDescriptor -SecurityDescriptor $sd</dev:code>
<command:returnValues>
<command:returnValue>
<dev:type>
<maml:name>System.Object</maml:name>
<maml:name>Security2.FileSystemInheritanceInfo</maml:name>
</dev:type>
<maml:description>
<maml:para>By default this cmdlet returns no output. With `-PassThru` it writes one `Security2.FileSystemInheritanceInfo` object per item, which reports the `AccessInheritanceEnabled` and `AuditInheritanceEnabled` state after the change.</maml:para>
@ -3403,7 +3411,7 @@ PS C:\&gt; Set-NTFSSecurityDescriptor -SecurityDescriptor $sd</dev:code>
<maml:name>ProcessPrivileges.PrivilegeAndAttributes</maml:name>
</dev:type>
<maml:description>
<maml:para>With `-PassThru`, the cmdlet writes the privilege collection of the current process. The pipeline enumerates it into one `ProcessPrivileges.PrivilegeAndAttributes` object per privilege, each with a `Privilege`, a `PrivilegeAttributes`, and a `PrivilegeState` property. Without `-PassThru`, the cmdlet writes nothing.</maml:para>
<maml:para>With `-PassThru`, the cmdlet writes one `ProcessPrivileges.PrivilegeAndAttributes` object per privilege of the current process, each with a `Privilege`, a `PrivilegeAttributes`, and a `PrivilegeState` property. Without `-PassThru`, the cmdlet writes nothing. Before 5.0.0, it wrote the privileges as one collection.</maml:para>
</maml:description>
</command:returnValue>
</command:returnValues>
@ -4140,10 +4148,10 @@ PS C:\&gt; Disable-Privileges</dev:code>
<command:returnValues>
<command:returnValue>
<dev:type>
<maml:name>Security2.FileSystemAccessRule2</maml:name>
<maml:name>Alphaleonis.Win32.Filesystem.FileInfo</maml:name>
</dev:type>
<maml:description>
<maml:para>The cmdlet does not return access rules. For every hashed file it writes the file object of that file, decorated with the type name `Alphaleonis.Win32.Filesystem.FileInfo+Hash` and extended with the `Hash` and `Algorithm` note properties, so all regular file properties such as `FullName`, `Name`, and `Length` remain available.</maml:para>
<maml:para>For every hashed file, the cmdlet writes the file object of that file, decorated with the type name `Alphaleonis.Win32.Filesystem.FileInfo+Hash` and extended with the `Hash` and `Algorithm` note properties, so all regular file properties such as `FullName`, `Name`, and `Length` remain available.</maml:para>
</maml:description>
</command:returnValue>
</command:returnValues>
@ -6938,10 +6946,18 @@ PS C:\Data&gt; Get-NTFSSecurityDescriptor</dev:code>
<command:returnValues>
<command:returnValue>
<dev:type>
<maml:name>System.Object</maml:name>
<maml:name>Alphaleonis.Win32.Filesystem.FileInfo</maml:name>
</dev:type>
<maml:description>
<maml:para>By default this cmdlet returns nothing. With `-PassThru $true` it returns an `Alphaleonis.Win32.Filesystem.FileInfo` or `Alphaleonis.Win32.Filesystem.DirectoryInfo` object for each item that it moved, pointing at the new location.</maml:para>
<maml:para>By default this cmdlet returns nothing. With `-PassThru $true` it returns a file object for each file that it moved, pointing at the new location.</maml:para>
</maml:description>
</command:returnValue>
<command:returnValue>
<dev:type>
<maml:name>Alphaleonis.Win32.Filesystem.DirectoryInfo</maml:name>
</dev:type>
<maml:description>
<maml:para>With `-PassThru $true` the cmdlet returns a folder object for each folder that it moved, pointing at the new location.</maml:para>
</maml:description>
</command:returnValue>
</command:returnValues>
@ -7300,7 +7316,7 @@ PS C:\Data&gt; Get-NTFSSecurityDescriptor</dev:code>
<maml:name>Alphaleonis.Win32.Filesystem.FileInfo</maml:name>
</dev:type>
<maml:description>
<maml:para>With `-PassThru`, the cmdlet writes a file object for the new link. The cmdlet writes that object type for a link to a folder as well. Without `-PassThru`, the cmdlet writes nothing.</maml:para>
<maml:para>With `-PassThru`, the cmdlet writes a file object for a new link to a file. Without `-PassThru`, the cmdlet writes nothing.</maml:para>
</maml:description>
</command:returnValue>
<command:returnValue>
@ -7308,7 +7324,7 @@ PS C:\Data&gt; Get-NTFSSecurityDescriptor</dev:code>
<maml:name>Alphaleonis.Win32.Filesystem.DirectoryInfo</maml:name>
</dev:type>
<maml:description>
<maml:para>The cmdlet does not write folder objects. A directory symbolic link is also returned as a file object.</maml:para>
<maml:para>With `-PassThru`, the cmdlet writes a folder object for a new link to a folder. Before 5.0.0, it wrote a file object for those links as well.</maml:para>
</maml:description>
</command:returnValue>
</command:returnValues>
@ -7545,10 +7561,18 @@ PS C:\Data&gt; Get-NTFSSecurityDescriptor</dev:code>
<command:returnValues>
<command:returnValue>
<dev:type>
<maml:name>System.Object</maml:name>
<maml:name>Alphaleonis.Win32.Filesystem.FileInfo</maml:name>
</dev:type>
<maml:description>
<maml:para>By default this cmdlet returns nothing. With `-PassThru` it returns an `Alphaleonis.Win32.Filesystem.FileInfo` or `Alphaleonis.Win32.Filesystem.DirectoryInfo` object for each item that it deleted.</maml:para>
<maml:para>By default this cmdlet returns nothing. With `-PassThru` it returns a file object for each file that it deleted.</maml:para>
</maml:description>
</command:returnValue>
<command:returnValue>
<dev:type>
<maml:name>Alphaleonis.Win32.Filesystem.DirectoryInfo</maml:name>
</dev:type>
<maml:description>
<maml:para>With `-PassThru` the cmdlet returns a folder object for each folder that it deleted.</maml:para>
</maml:description>
</command:returnValue>
</command:returnValues>
@ -9508,7 +9532,7 @@ PS C:\&gt; Set-NTFSSecurityDescriptor -SecurityDescriptor $sd</dev:code>
<command:returnValues>
<command:returnValue>
<dev:type>
<maml:name>System.Object</maml:name>
<maml:name>Security2.FileSystemInheritanceInfo</maml:name>
</dev:type>
<maml:description>
<maml:para>By default this cmdlet returns no output. With `-PassThru` it writes one `Security2.FileSystemInheritanceInfo` object per item, which reports the `AccessInheritanceEnabled` and `AuditInheritanceEnabled` state after the change.</maml:para>
@ -10085,18 +10109,10 @@ PS C:\&gt; Set-NTFSSecurityDescriptor -SecurityDescriptor $sd</dev:code>
<command:returnValues>
<command:returnValue>
<dev:type>
<maml:name>Alphaleonis.Win32.Filesystem.FileInfo</maml:name>
</dev:type>
<maml:description>
<maml:para>`Test-Path2` does not write file objects. For each path it writes a single `System.Boolean` value that is `$true` when the item exists and matches `-PathType`, and `$false` otherwise.</maml:para>
</maml:description>
</command:returnValue>
<command:returnValue>
<dev:type>
<maml:name>Alphaleonis.Win32.Filesystem.DirectoryInfo</maml:name>
<maml:name>System.Boolean</maml:name>
</dev:type>
<maml:description>
<maml:para>`Test-Path2` does not write folder objects either. A folder is reported through the same `System.Boolean` result as a file.</maml:para>
<maml:para>For each path, the cmdlet writes `$true` when the item exists and matches `-PathType`, and `$false` otherwise.</maml:para>
</maml:description>
</command:returnValue>
</command:returnValues>

87
Tests/OutputTypes.Tests.ps1

@ -0,0 +1,87 @@
<#
Tests the output types of the cmdlets of the module built in NTFSSecurity\bin\Release: the [OutputType] that
Get-Command reports, and the objects that -PassThru writes. Tests that need a privilege skip without it and run
in CI, whose runners are elevated.
#>
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
'PSUseDeclaredVarsMoreThanAssignments', '', Justification = 'Pester shares variables between blocks.'
)]
param ()
BeforeDiscovery {
Import-Module -Name (Join-Path -Path $PSScriptRoot -ChildPath 'TestHelpers.psm1') -Force
$holdsBackupPrivilege = Test-PrivilegeHeld -Name 'SeBackupPrivilege'
$canCreateSymbolicLinks = Test-PrivilegeHeld -Name 'SeCreateSymbolicLinkPrivilege'
$itemTypes = @('Alphaleonis.Win32.Filesystem.FileInfo', 'Alphaleonis.Win32.Filesystem.DirectoryInfo')
$declaredTypes = @(
@{ Name = 'Test-Path2'; Types = @('System.Boolean') }
@{ Name = 'Get-FileHash2'; Types = @('Alphaleonis.Win32.Filesystem.FileInfo') }
@{ Name = 'Add-NTFSAudit'; Types = @('Security2.FileSystemAuditRule2') }
@{ Name = 'Remove-NTFSAudit'; Types = @('Security2.FileSystemAuditRule2') }
@{ Name = 'Copy-Item2'; Types = $itemTypes }
@{ Name = 'Move-Item2'; Types = $itemTypes }
@{ Name = 'Remove-Item2'; Types = $itemTypes }
@{ Name = 'Enable-NTFSAccessInheritance'; Types = @('Security2.FileSystemInheritanceInfo') }
@{ Name = 'Disable-NTFSAccessInheritance'; Types = @('Security2.FileSystemInheritanceInfo') }
@{ Name = 'Enable-NTFSAuditInheritance'; Types = @('Security2.FileSystemInheritanceInfo') }
@{ Name = 'Disable-NTFSAuditInheritance'; Types = @('Security2.FileSystemInheritanceInfo') }
@{ Name = 'Set-NTFSInheritance'; Types = @('Security2.FileSystemInheritanceInfo') }
)
}
BeforeAll {
Import-Module -Name (Join-Path -Path $PSScriptRoot -ChildPath 'TestHelpers.psm1') -Force
$modulePath = Join-Path -Path $PSScriptRoot -ChildPath '..\NTFSSecurity\bin\Release\NTFSSecurity.psd1'
Import-Module -Name $modulePath -Force -ErrorAction Stop
$sandbox = New-TestSandbox -Name 'OutputTypes'
Push-Location -LiteralPath $sandbox
}
AfterAll {
Pop-Location
Remove-TestSandbox -Sandbox $sandbox
Remove-Module -Name NTFSSecurity -Force -ErrorAction SilentlyContinue
}
Describe 'Declared output types' {
It '<Name> should declare the type of the objects it writes' -ForEach $declaredTypes {
@((Get-Command -Name $Name).OutputType.Name) | Should -Be $Types
}
}
Describe 'Privilege cmdlets with -PassThru' {
AfterEach {
Disable-Privileges -ErrorAction SilentlyContinue -WarningAction SilentlyContinue
}
# Before 5.0.0, -PassThru wrote the privileges as one collection.
It 'Enable-Privileges should write one object per privilege' {
$result = @(Enable-Privileges -PassThru -ErrorAction SilentlyContinue)
$result.Count | Should -BeGreaterThan 1
$result | ForEach-Object -Process { $_ | Should -BeOfType [ProcessPrivileges.PrivilegeAndAttributes] }
}
It 'Disable-Privileges should write one object per privilege' -Skip:(-not $holdsBackupPrivilege) {
Enable-Privileges -ErrorAction SilentlyContinue
$result = @(Disable-Privileges -PassThru -WarningAction SilentlyContinue)
$result.Count | Should -BeGreaterThan 1
$result | ForEach-Object -Process { $_ | Should -BeOfType [ProcessPrivileges.PrivilegeAndAttributes] }
}
}
Describe 'New-NTFSSymbolicLink with -PassThru' {
# Before 5.0.0, the cmdlet returned a file object for a link to a folder as well.
It 'Should return a folder object for a link to a folder' -Skip:(-not $canCreateSymbolicLinks) {
$folder = New-TestSandboxItem -Sandbox $sandbox -Name 'Target' -Directory
$link = Join-Path -Path $sandbox -ChildPath 'FolderLink'
Assert-TestSandboxPath -Sandbox $sandbox -Path $link
$result = New-NTFSSymbolicLink -Path $link -Target $folder -PassThru
$result | Should -BeOfType [Alphaleonis.Win32.Filesystem.DirectoryInfo]
}
}
Loading…
Cancel
Save