microsoft / PSRule

Validate infrastructure as code (IaC) and objects using PowerShell rules.
https://microsoft.github.io/PSRule/v2/
MIT License
395 stars 49 forks source link

Cannot execute rule using Invoke-PSRule #672

Closed kuhaqzf1 closed 3 years ago

kuhaqzf1 commented 3 years ago

Description of the issue

When I try to execute a rule using Invoke-PSRule command I get Access to the path 'c:\users\fhaq\AppData\Local\Application Data' is denied. At C:\Program Files (x86)\WindowsPowerShell\Modules\PSRule\1.1.0\PSRule.psm1:1677 char:17

Steps to reproduce the issue:

$resources | Invoke-PSRule -Option .\ps-rule.yaml Expected behaviour

Execute rule and pipe the target object to Invoke-PSRule. Error output

Access to the path 'c:\users\fhaq\AppData\Local\Application Data' is denied. At C:\Program Files (x86)\WindowsPowerShell\Modules\PSRule\1.1.0\PSRule.psm1:1677 char:17

Captured output from $PSVersionTable:

Name Value


PSVersion 5.1.17763.1490
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.17763.1490
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
Additional context

I get the same error if I try to execute any rule with Invoke-PSRule

Define objects to validate

$items = @(); $items += [PSCustomObject]@{ Name = 'Fridge' }; $items += [PSCustomObject]@{ Name = 'Apple' };

Validate each item using rules saved in current working path

$items | Invoke-PSRule;

BernieWhite commented 3 years ago

@kuhaqzf1 Thank you for reporting the issue.

I think this is a general PowerShell issue as Invoke-PSRule does not write to any files by default unless you specify -OutputPath.

Can you please try Get-ChildItem -Path 'C:\Program Files (x86)\WindowsPowerShell\Modules\PSRule\' -Recurse | Unblock-File; within an administrator / elevated PowerShell prompt.

kuhaqzf1 commented 3 years ago

I am past that error. Thanks for your assistance. However; now I am getting this error: Invoke-PSRule : Cannot bind argument to parameter 'InputObject' because it is null. At line:1 char:14 Invoke-PSRule : Cannot bind argument to parameter 'InputObject' because it is null. At line:1 char:14

PS C:\users\fhaq>

BernieWhite commented 3 years ago

@kuhaqzf1 The error is suggesting that $resources is null or the items on $resources contains null values. -InputObject only accepts non-null values.

Are you able to share what you are using to populate $resources?

github-actions[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs within 7 days. Thank you for your contributions.

github-actions[bot] commented 3 years ago

This issue was closed because it has not had any recent activity.