Export-AzPolicyAssignmentDafa returning 0 assignments in azure pipeline #3478
Replies: 2 comments 5 replies
-
Hi @Preetha878 thanks for the question. Let me summarise the issue to make sure I understand the question and where you are having an issue. You have tried running the following locally and it works as expected:
When trying this in Azure Pipelines you are having an issue, you have tried the Have I understood you correctly? There is some changes in the latest version of PSRule for Azure (v1.45.0) so are you able to let me know what version of PSRule for Azure you are using? From
Also it's important to note, that only the You can choose to run both the Next steps:
- task: AzurePowerShell@5
inputs:
# Set this input to the computed value
azureSubscription: '<your_connection>'
azurePowerShellVersion: 'LatestVersion'
scriptType: 'InlineScript'
inline: |
Export-AzPolicyAssignmentData -Scope <nnn> -Verbose | ForEach-Object { Export-AzPolicyAssignmentRuleData -Verbose -AssignmentFile $_ } Are you able to provide further information based on the results of running the pipeline. |
Beta Was this translation helpful? Give feedback.
-
Hi @BernieWhite , Thanks for the quick response In local im using PSRule.Rules.Azure version 1.44.2 I tried with the following task
Below is my pipeline output: VERBOSE: Command [Set-AzContext] succeeded. with pwsh:true for AzurePowerShell@5 Im getting the below results 2 �[33;1mDEBUG: ClientSecretCredential.GetToken succeeded. Scopes: [ https://management.core.windows.net//.default ] ParentRequestId: ExpiresOn: 2025-07-16T05:51:34.4462006+00:00�[0m |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I'm trying to convert my policy as rule and validate against my bicep template
Steps followed:
Step up in local:
Powershell version 5 nd 7 both are working as expected
Modules installed: Az.Accounts, Az.Resources (6.7.0), PSRule.Azure....
Get-AzPolicyAssignment -Scope - got expected result
Iterated through assignments from above command and provided as input to. Below command
Export-AzPolicyAssignmentData -name "assignment name" -Scope "scopeofassogmment"
Able to get the result and create the json file and convert as ps compatible rules and validate against bicep
But in azure pipeline
I used below task and test with both psversion 5 and 7
Issue:
-task : Powershell@2 - I tried to authenticate using service principle and installed modules like Az.Accounts and Az.Resources and for PS rules and also imported and used Get-AzPolicyAssignment and able to get output but this Export-AzPolicyAssignmentData is giving "0 assignments found " when I set pwsh to true (powershell version 7) and Connect-AzAccount is not able to connect for Export-AzPolicyAssignmentData for pwsh:false (powershell version 5)
Same issue as PowerShell@2 for AzurePowerShell@5
I tried installing module for Az.Resources explicitly with version 6.7.0 but couldn't override the default one from Az module that comes with AzurePowerShell@5
Pls guide me here
I'm basically blocked here
Thanks in advance
Beta Was this translation helpful? Give feedback.
All reactions