diff --git a/CHANGELOG.md b/CHANGELOG.md
index 4a1891b..ab9003a 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -177,5 +177,9 @@ The format is based on
automatic variable; the cmdlets now read the current location from the
session, and only for a relative path
([#86](https://github.com/raandree/NTFSSecurity/issues/86))
+- Fix file and folder objects passed by position, such as
+ `Get-NTFSOwner $folder`, which Windows PowerShell bound as the name of the
+ item, so the cmdlets looked for it in the current location
+ ([#88](https://github.com/raandree/NTFSSecurity/issues/88))
[Unreleased]: https://github.com/raandree/NTFSSecurity/compare/4.2.6...HEAD
diff --git a/NTFSSecurity/AccessCmdlets/AddAccess.cs b/NTFSSecurity/AccessCmdlets/AddAccess.cs
index 4770aa9..f503aaa 100644
--- a/NTFSSecurity/AccessCmdlets/AddAccess.cs
+++ b/NTFSSecurity/AccessCmdlets/AddAccess.cs
@@ -23,6 +23,7 @@ namespace NTFSSecurity
[Parameter(Mandatory = true, Position = 1, ValueFromPipeline = true, ValueFromPipelineByPropertyName = true, ParameterSetName = "PathComplex")]
[ValidateNotNullOrEmpty]
[Alias("FullName")]
+ [FileSystemPathTransformation]
public string[] Path
{
get { return paths.ToArray(); }
diff --git a/NTFSSecurity/AccessCmdlets/ClearAccess.cs b/NTFSSecurity/AccessCmdlets/ClearAccess.cs
index 9e96a39..1e4a1c6 100644
--- a/NTFSSecurity/AccessCmdlets/ClearAccess.cs
+++ b/NTFSSecurity/AccessCmdlets/ClearAccess.cs
@@ -13,6 +13,7 @@ namespace NTFSSecurity
[Parameter(Mandatory = true, Position = 1, ValueFromPipeline = true, ValueFromPipelineByPropertyName = true, ParameterSetName = "Path")]
[ValidateNotNullOrEmpty]
[Alias("FullName")]
+ [FileSystemPathTransformation]
public string[] Path
{
get { return paths.ToArray(); }
diff --git a/NTFSSecurity/AccessCmdlets/GetAccess.cs b/NTFSSecurity/AccessCmdlets/GetAccess.cs
index f010e18..1239306 100644
--- a/NTFSSecurity/AccessCmdlets/GetAccess.cs
+++ b/NTFSSecurity/AccessCmdlets/GetAccess.cs
@@ -20,6 +20,7 @@ namespace NTFSSecurity
[Parameter(Position = 1, ValueFromPipeline = true, ValueFromPipelineByPropertyName = true, ParameterSetName = "Path")]
[ValidateNotNullOrEmpty]
[Alias("FullName")]
+ [FileSystemPathTransformation]
public string[] Path
{
get { return paths.ToArray(); }
diff --git a/NTFSSecurity/AccessCmdlets/GetEffectiveAccess.cs b/NTFSSecurity/AccessCmdlets/GetEffectiveAccess.cs
index bf1334c..96eb1db 100644
--- a/NTFSSecurity/AccessCmdlets/GetEffectiveAccess.cs
+++ b/NTFSSecurity/AccessCmdlets/GetEffectiveAccess.cs
@@ -20,6 +20,7 @@ namespace NTFSSecurity
[Parameter(Position = 1, ValueFromPipeline = true, ValueFromPipelineByPropertyName = true, ParameterSetName = "Path")]
[ValidateNotNullOrEmpty]
[Alias("FullName")]
+ [FileSystemPathTransformation]
public string[] Path
{
get { return paths.ToArray(); }
diff --git a/NTFSSecurity/AccessCmdlets/RemoveAccess.cs b/NTFSSecurity/AccessCmdlets/RemoveAccess.cs
index bd4c04d..a1c566b 100644
--- a/NTFSSecurity/AccessCmdlets/RemoveAccess.cs
+++ b/NTFSSecurity/AccessCmdlets/RemoveAccess.cs
@@ -24,6 +24,7 @@ namespace NTFSSecurity
[Parameter(Mandatory = true, Position = 1, ValueFromPipeline = true, ValueFromPipelineByPropertyName = true, ParameterSetName = "PathComplex")]
[ValidateNotNullOrEmpty]
[Alias("FullName")]
+ [FileSystemPathTransformation]
public string[] Path
{
get { return paths.ToArray(); }
diff --git a/NTFSSecurity/AuditCmdlets/AddAudit.cs b/NTFSSecurity/AuditCmdlets/AddAudit.cs
index d5a11f2..f8b8584 100644
--- a/NTFSSecurity/AuditCmdlets/AddAudit.cs
+++ b/NTFSSecurity/AuditCmdlets/AddAudit.cs
@@ -23,6 +23,7 @@ namespace NTFSSecurity
[Parameter(Mandatory = true, Position = 1, ValueFromPipeline = true, ValueFromPipelineByPropertyName = true, ParameterSetName = "PathComplex")]
[ValidateNotNullOrEmpty]
[Alias("FullName")]
+ [FileSystemPathTransformation]
public string[] Path
{
get { return paths.ToArray(); }
diff --git a/NTFSSecurity/AuditCmdlets/ClearAudit.cs b/NTFSSecurity/AuditCmdlets/ClearAudit.cs
index 622e5d4..a6f7614 100644
--- a/NTFSSecurity/AuditCmdlets/ClearAudit.cs
+++ b/NTFSSecurity/AuditCmdlets/ClearAudit.cs
@@ -13,6 +13,7 @@ namespace NTFSSecurity
[Parameter(Mandatory = true, Position = 1, ValueFromPipeline = true, ValueFromPipelineByPropertyName = true, ParameterSetName = "Path")]
[ValidateNotNullOrEmpty]
[Alias("FullName")]
+ [FileSystemPathTransformation]
public string[] Path
{
get { return paths.ToArray(); }
diff --git a/NTFSSecurity/AuditCmdlets/GetAudit.cs b/NTFSSecurity/AuditCmdlets/GetAudit.cs
index c569212..3c6c58c 100644
--- a/NTFSSecurity/AuditCmdlets/GetAudit.cs
+++ b/NTFSSecurity/AuditCmdlets/GetAudit.cs
@@ -20,6 +20,7 @@ namespace NTFSSecurity
[Parameter(Position = 1, ValueFromPipeline = true, ValueFromPipelineByPropertyName = true, ParameterSetName = "Path")]
[ValidateNotNullOrEmpty]
[Alias("FullName")]
+ [FileSystemPathTransformation]
public string[] Path
{
get { return paths.ToArray(); }
diff --git a/NTFSSecurity/AuditCmdlets/RemoveAudit.cs b/NTFSSecurity/AuditCmdlets/RemoveAudit.cs
index c9b618b..9d88c2b 100644
--- a/NTFSSecurity/AuditCmdlets/RemoveAudit.cs
+++ b/NTFSSecurity/AuditCmdlets/RemoveAudit.cs
@@ -24,6 +24,7 @@ namespace NTFSSecurity
[Parameter(Mandatory = true, Position = 1, ValueFromPipeline = true, ValueFromPipelineByPropertyName = true, ParameterSetName = "PathComplex")]
[ValidateNotNullOrEmpty]
[Alias("FullName")]
+ [FileSystemPathTransformation]
public string[] Path
{
get { return paths.ToArray(); }
diff --git a/NTFSSecurity/BaseCmdlets.cs b/NTFSSecurity/BaseCmdlets.cs
index 36aad2f..3ccf04f 100644
--- a/NTFSSecurity/BaseCmdlets.cs
+++ b/NTFSSecurity/BaseCmdlets.cs
@@ -335,4 +335,55 @@ namespace NTFSSecurity
base.WriteDebug(args == null || args.Length == 0 ? text : string.Format(text, args));
}
}
-}
+
+ ///
+ /// Converts file and folder objects to their full path. Windows PowerShell binds an object that is passed by
+ /// position to a string parameter through ToString, which returns only the name of a child item, so the cmdlet
+ /// resolved it against the current location (#88).
+ ///
+ [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field)]
+ public sealed class FileSystemPathTransformationAttribute : ArgumentTransformationAttribute
+ {
+ ///
+ /// Returns the full path of a file or folder object, or of each one in a collection, and any other value
+ /// unchanged.
+ ///
+ /// The engine APIs of the session.
+ /// The argument to transform.
+ /// The transformed argument.
+ public override object Transform(EngineIntrinsics engineIntrinsics, object inputData)
+ {
+ var input = inputData is PSObject ? ((PSObject)inputData).BaseObject : inputData;
+
+ if (input is string || !(input is IEnumerable))
+ {
+ return ToPath(inputData);
+ }
+
+ var result = new List