Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit e336c4d

Browse files
Add Azure Policy Compliance Data script
1 parent ddc9459 commit e336c4d

File tree

1 file changed

+81
-0
lines changed

1 file changed

+81
-0
lines changed
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
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+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /