Unable to export the azure policy definitions metadata like available effects, Definitions type

Prateek Rana 60 Reputation points
2023-04-25T06:52:48.2633333+00:00

Hi, I Exported the azure policy definitions through the azure PowerShell in CSV format, I got the details but metadata like available effects, Definitions type data is not fetched in the CSV file (Attributes details are missing). File attached for the information. Below is the script through which is used to exported the Policy definitions. Get-AzPolicyDefinition | Select-Object -ExpandProperty properties | Select-Object -Property Metadata, DisplayName, Description, PolicyType, Definitiontype, AvailableEffects | Export-CSV "./policyDefinitionn.csv" Troubleshooting done:

  1. cleared the cache of the browser but didn't help
  2. tried with different browser didn't help
  3. tried with admin console that also didn't help
  4. in admin console below is error am getting.
PS C:\WINDOWS\system32> $policyDefinitions | Export-Csv -Path 'D:\PolicyDefinitions.csv'
Export-Csv : Cannot bind argument to parameter 'InputObject' because it is null.
At line:1 char:22
+ $policyDefinitions | Export-Csv -Path 'D:\PolicyDefinitions.csv'
+                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidData: (:) [Export-Csv], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.ExportCsvCo
   mmand


PS C:\WINDOWS\system32> $policyDefinitions | Export-Csv -Path 'C:\PolicyDefinitions.csv'
Export-Csv : Cannot bind argument to parameter 'InputObject' because it is null.
At line:1 char:22
+ $policyDefinitions | Export-Csv -Path 'C:\PolicyDefinitions.csv'
+                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidData: (:) [Export-Csv], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.ExportCsvCo
   mmand

User's image

Azure Policy
Azure Policy
An Azure service that is used to implement corporate governance and standards at scale for Azure resources.
788 questions
{count} votes

Accepted answer
  1. tbgangav-MSFT 10,381 Reputation points
    2023-04-25T09:55:13.1166667+00:00

    Hi @Prateek Rana ,

    In Azure Portal, we have a column named 'Definition type' under 'Definitions' tile in Azure Policies which has value either as 'Policy' or 'Initiative' but in Azure PowerShell Get-AzPolicyDefinition gets policy definitions whereas Get-AzPolicySetDefinition gets policy set definitions i.e., policy set definitions under initiatives so you may leverage both the cmdlets and collate the list and then export it to CSV at the end.

    That takes care of 'DefinitionType'. Next, when you say 'AvailableEffects', did you mean allowed effect values under a definition which are provided under parameters property? If yes, then you could get them using below code sample. Same way you may get it for policy sets as well.

    Code sample:

    Get-AzPolicyDefinition | Select-Object @{Name="Metadata"; Expression={$_.Properties.Metadata}}, @{Name="DisplayName"; Expression={$_.Properties.DisplayName}}, @{Name="Description"; Expression={$_.Properties.Description}}, @{Name="PolicyType"; Expression={$_.Properties.PolicyType}}, @{Name="Definitiontype"; Expression={"Policy"}}, @{Name="AvailableEffects"; Expression={$_.Properties.Parameters.effect.allowedValues}} 
    

    Output sample: User's image

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful