PSRule icon indicating copy to clipboard operation
PSRule copied to clipboard

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

Open BernieWhite opened this issue 2 years ago • 2 comments

Discussed in https://github.com/microsoft/PSRule/discussions/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 https://github.com/microsoft/PSRule/blob/e4f8bbe9eb4eb17a1002bb107091ea3f33ed2939/src/PSRule/PSRule.Format.ps1xml#L259-L297

BernieWhite avatar Jan 03 '24 15:01 BernieWhite

@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.

tonyskidmore avatar Feb 01 '24 15:02 tonyskidmore

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

BernieWhite avatar Feb 01 '24 17:02 BernieWhite

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

BernieWhite avatar Apr 14 '24 23:04 BernieWhite