diff --git a/Engine/Commands/InvokeFormatterCommand.cs b/Engine/Commands/InvokeFormatterCommand.cs index c0d9fd168..d08d8c817 100644 --- a/Engine/Commands/InvokeFormatterCommand.cs +++ b/Engine/Commands/InvokeFormatterCommand.cs @@ -25,14 +25,14 @@ public class InvokeFormatterCommand : PSCmdlet, IOutputWriter /// /// *NOTE*: Unlike ScriptBlock parameter, the ScriptDefinition parameter require a string value. /// - [ParameterAttribute(Mandatory = true, Position = 1)] + [ParameterAttribute(Mandatory = true, ValueFromPipeline = true, ValueFromPipelineByPropertyName = true, Position = 1)] [ValidateNotNull] public string ScriptDefinition { get; set; } /// /// A settings hashtable or a path to a PowerShell data file (.psd1) file that contains the settings. /// - [Parameter(Mandatory = false, Position = 2)] + [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, Position = 2)] [ValidateNotNull] public object Settings { get; set; } = defaultSettingsPreset; @@ -44,7 +44,7 @@ public class InvokeFormatterCommand : PSCmdlet, IOutputWriter /// end column number. These numbers must be greater than 0. /// /// - [Parameter(Mandatory = false, Position = 3)] + [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, Position = 3)] [ValidateNotNull] [ValidateCount(4, 4)] public int[] Range { get; set; } diff --git a/Tests/Engine/InvokeFormatter.tests.ps1 b/Tests/Engine/InvokeFormatter.tests.ps1 index 7fc0703fc..dcc0a6174 100644 --- a/Tests/Engine/InvokeFormatter.tests.ps1 +++ b/Tests/Engine/InvokeFormatter.tests.ps1 @@ -14,6 +14,19 @@ Describe "Invoke-Formatter Cmdlet" { } } + Context 'Accept Value from Pipeline' { + It 'Value from Pipeline' { + 'foo' | Invoke-Formatter | Should -Be 'foo' + } + It 'Value from Pipeline by Property Name with just the mandatory ScriptDefinition parameter' { + [pscustomobject]@{ 'ScriptDefinition' = 'foo' } | Invoke-Formatter | Should -Be 'foo' + } + It 'Value from Pipeline by Property Name with all parameters' { + [pscustomobject]@{ ScriptDefinition = 'foo'; Settings = @(); Range = 1, 1, 1, 4 } | + Invoke-Formatter | Should -Be 'foo' + } + } + Context "When positional parameters are given" { It "Should use the positional parameters" { $def = @"