File tree 1 file changed +81
-0
lines changed
AZURE-Get-PolicyComplianceData
1 file changed +81
-0
lines changed Original file line number Diff line number Diff line change
1
+
2
+ <# PSScriptInfo
3
+
4
+ .VERSION 1.0
5
+
6
+ .GUID f2d5adaf-ed37-4dcc-96d5-2ac72b770cf8
7
+
8
+ .AUTHOR Francois-Xavier Cat
9
+
10
+ .COMPANYNAME
11
+
12
+ .COPYRIGHT
13
+
14
+ .TAGS
15
+
16
+ .LICENSEURI
17
+
18
+ .PROJECTURI
19
+ https://github.com/lazywinadmin/PowerShell
20
+
21
+ .ICONURI
22
+
23
+ .EXTERNALMODULEDEPENDENCIES
24
+
25
+ .REQUIREDSCRIPTS
26
+
27
+ .EXTERNALSCRIPTDEPENDENCIES
28
+
29
+ .RELEASENOTES
30
+
31
+ .PRIVATEDATA
32
+
33
+ #>
34
+
35
+ <#
36
+ . SYNOPSIS
37
+ Retrieve Azure Policy Compliance Data for a specific Assignment under a specific ManagementGroupName
38
+ . DESCRIPTION
39
+ Retrieve Azure Policy Compliance Data for a specific Assignment under a specific ManagementGroupName
40
+ This will also retrieve the subscription name
41
+
42
+ This script assume you are already connected and authenticated to Azure.
43
+
44
+ . PARAMETER ManagementGroupName
45
+ Specify the ManagementGroupName
46
+
47
+ . PARAMETER AssignmentID
48
+ Specify the AssignmentID
49
+
50
+ . EXAMPLE
51
+ Get-PolicyComplianceData.ps1 -ManagementGroupName <id> -AssignmentID <id>
52
+
53
+ . LINK
54
+ https://github.com/lazywinadmin/PowerShell
55
+
56
+ #>
57
+ [CmdletBinding ()]
58
+ Param (
59
+ $ManagementGroupName ,
60
+ $AssignmentID
61
+ )
62
+ try {
63
+ # Retrieve the Compliance data
64
+ $State = Get-AzPolicyState - ManagementGroupName $ManagementGroupName - Filter " (AssignmentID eq $AssignmentID )"
65
+
66
+ $SubscriptionNames = $State | Group-Object - Property SubscriptionId | ForEach-Object - Process {
67
+ Get-AzSubscription - SubscriptionId $_.Name
68
+ }
69
+
70
+ $State | Select-Object - Property * , @ {
71
+ Label = ' SubscriptionName' ;
72
+ Expression = @ {
73
+ # keep current state in var
74
+ $CurrentState = $_
75
+ # retrieve sub name
76
+ ($SubscriptionNames | Where-Object - Filter {$_.id -eq $currentState.subscriptionid }).name
77
+ }
78
+ }
79
+ }catch {
80
+ throw $_
81
+ }
You can’t perform that action at this time.
0 commit comments