microsoft / PSRule

Validate infrastructure as code (IaC) and objects using PowerShell rules.

Home Page:https://microsoft.github.io/PSRule/v2/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cannot process argument because the value of argument "name" is not valid

BernieWhite opened this issue · comments

Discussed in #1722

Originally posted by paulmcclbg January 3, 2024
If I run the following:

Assert-PSRule -InputPath ./test-sample-1.json -Module PSRule.Rules.Azure

then the command runs fine and I get rule results outputted to the terminal (8 passed, 2 failed)

As soon as I change to

Invoke-PSRule -InputPath ./test-sample-1.json -Module PSRule.Rules.Azure
I get this error:

format-default: Cannot process argument because the value of argument "name" is not valid. Change the value of the "name" argument and run the operation again.

Can you please explain ? I want to use Invoke-PSRule due to invokation through Pester.

Note: Test-PSRuleTarget also runs fine and returns False.

There is an issue with the default formatting configuration in

<View>
<Name>PSRule.Rules.RuleRecord</Name>
<ViewSelectedBy>
<TypeName>PSRule.Rules.RuleRecord</TypeName>
</ViewSelectedBy>
<GroupBy>
<PropertyName>TargetName</PropertyName>
</GroupBy>
<TableControl>
<TableHeaders>
<TableColumnHeader>
<Label AssemblyName="Microsoft.PSRule.Core" BaseName="PSRule.Resources.ViewStrings" ResourceId="RuleName"/>
<Width>35</Width>
</TableColumnHeader>
<TableColumnHeader>
<Label AssemblyName="Microsoft.PSRule.Core" BaseName="PSRule.Resources.ViewStrings" ResourceId="Outcome"/>
<Width>10</Width>
</TableColumnHeader>
<TableColumnHeader>
<Label AssemblyName="Microsoft.PSRule.Core" BaseName="PSRule.Resources.ViewStrings" ResourceId="Recommendation"/>
</TableColumnHeader>
</TableHeaders>
<TableRowEntries>
<TableRowEntry>
<TableColumnItems>
<TableColumnItem>
<PropertyName>Name</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>Outcome</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>Recommendation</PropertyName>
</TableColumnItem>
</TableColumnItems>
</TableRowEntry>
</TableRowEntries>
</TableControl>
</View>

@BernieWhite I have just started looking at PSRule and have come across this issue trying to get started using PowerShell 7.4.1.

Export-AzRuleData -OutputPath "$PWD/out/"
Invoke-PSRule -InputPath "$PWD/out/" -Module 'PSRule.Rules.Azure'

format-default: Cannot process argument because the value of argument "name" is not valid. Change the value of the "name" argument and run the operation again.

If I run the same command from PowerShell 7.3..11 it works, i.e., I see output:

cmd.exe
cd C:\tools\PowerShell-7.3.11
pwsh

Get-Host

Name             : ConsoleHost
Version          : 7.3.11
InstanceId       : 0faf6a9e-eab1-47d2-aa9e-95ce70c48f2e
UI               : System.Management.Automation.Internal.Host.InternalHostUserInterface
CurrentCulture   : en-GB
CurrentUICulture : en-GB
PrivateData      : Microsoft.PowerShell.ConsoleHost+ConsoleColorProxy
DebuggerEnabled  : True
IsRunspacePushed : False
Runspace         : System.Management.Automation.Runspaces.LocalRunspace

Invoke-PSRule -InputPath "$PWD/out/" -Module 'PSRule.Rules.Azure'

The problem for me is this is running in CD agents that have PowerShell 7.4.1 installed by default and I didn't want to start building containers just to do some initial POC testing in a pipeline.

Thanks for the detail @tonyskidmore.

Currently we believe this is a regression introduced in PS 7.4.x. PowerShell/PowerShell#21147

The issue affects the default view set by PSRule. The issue is noticable when running with the cmdlet interactively, and shouldn't affect most automated pipelines.

As a workaround until the fix ships you can update your command-line to select the specific properties you want as follows:

Invoke-PSRule -InputPath "$PWD/out/" -Module 'PSRule.Rules.Azure' | Select-Object RuleName, Outcome, Recommendation

This issue is fixed in PowerShell v7.4.2. Affected versions of PowerShell include v7.4.0 - v7.4.1.