|
| 1 | +<# |
| 2 | +.SYNOPSIS |
| 3 | + Test that the provided Azure AD Assessment package has the necessary content |
| 4 | +.DESCRIPTION |
| 5 | + Test that the provided Azure AD Assessment package has the necessary content |
| 6 | +.EXAMPLE |
| 7 | + PS C:\>Test-AADAssessmentPackage 'C:\AzureADAssessmentData-contoso.aad' |
| 8 | + Test that the package for contoso has the necesary content for the assessment. |
| 9 | +.INPUTS |
| 10 | + System.String |
| 11 | +#> |
| 12 | +function Test-AADAssessmentPackage { |
| 13 | + [CmdletBinding()] |
| 14 | + param |
| 15 | + ( |
| 16 | + # Path to the file where the exported events will be stored |
| 17 | + [Parameter(Mandatory = $true)] |
| 18 | + [string] $Path, |
| 19 | + # Reports should have been generated |
| 20 | + [Parameter(Mandatory = $false)] |
| 21 | + [bool] $SkippedReportOutput |
| 22 | + ) |
| 23 | + |
| 24 | + if (!(Test-Path -path $Path)) { |
| 25 | + Write-Warning "Assessment package not found" |
| 26 | + return $false |
| 27 | + } |
| 28 | + |
| 29 | + $fullPath = Convert-Path $Path |
| 30 | + |
| 31 | + $requiredEntries = @( |
| 32 | + "AAD-*/administrativeUnits.csv", |
| 33 | + "AAD-*/AppCredentialsReport.csv", |
| 34 | + "AAD-*/applications.json", |
| 35 | + "AAD-*/appRoleAssignments.csv", |
| 36 | + "AAD-*/conditionalAccessPolicies.json", |
| 37 | + "AAD-*/ConsentGrantReport.csv", |
| 38 | + "AAD-*/emailOTPMethodPolicy.json", |
| 39 | + "AAD-*/groups.csv", |
| 40 | + "AAD-*/namedLocations.json", |
| 41 | + "AAD-*/NotificationsEmailsReport.csv", |
| 42 | + "AAD-*/oauth2PermissionGrants.csv", |
| 43 | + "AAD-*/organization.json", |
| 44 | + "AAD-*/RoleAssignmentReport.csv", |
| 45 | + "AAD-*/roleDefinitions.csv", |
| 46 | + "AAD-*/servicePrincipals.csv", |
| 47 | + "AAD-*/servicePrincipals.json", |
| 48 | + "AAD-*/subscribedSkus.json", |
| 49 | + "AAD-*/userRegistrationDetails.json", |
| 50 | + "AAD-*/users.csv", |
| 51 | + "AzureADAssessment.json" |
| 52 | + ) |
| 53 | + |
| 54 | + if ($SkippedReportOutput) { |
| 55 | + $requiredEntries = @( |
| 56 | + "AAD-*/administrativeUnits.csv", |
| 57 | + "AAD-*/applicationData.xml", |
| 58 | + "AAD-*/appRoleAssignmentData.xml", |
| 59 | + "AAD-*/conditionalAccessPolicies.json", |
| 60 | + "AAD-*/directoryRoleData.xml" |
| 61 | + "AAD-*/emailOTPMethodPolicy.json", |
| 62 | + "AAD-*/groupData.xml", |
| 63 | + "AAD-*/namedLocations.json", |
| 64 | + "AAD-*/oauth2PermissionGrantData.xml", |
| 65 | + "AAD-*/organization.json", |
| 66 | + "AAD-*/roleAssignmentSchedulesData.xml", |
| 67 | + "AAD-*/roleDefinitions.csv", |
| 68 | + "AAD-*/roleEligibilitySchedulesData.xml", |
| 69 | + "AAD-*/servicePrincipalData.xml", |
| 70 | + "AAD-*/subscribedSkus.json", |
| 71 | + "AAD-*/userData.xml", |
| 72 | + "AAD-*/userRegistrationDetails.json", |
| 73 | + "AzureADAssessment.json" |
| 74 | + ) |
| 75 | + } |
| 76 | + |
| 77 | + $entries = [IO.Compression.ZipFile]::OpenRead($fullPath).Entries |
| 78 | + |
| 79 | + $effectiveEntries = $entries | Where-Object { $_.Length -gt 0} |
| 80 | + |
| 81 | + $validPackage = $true |
| 82 | + foreach($requiredEntry in $requiredEntries) { |
| 83 | + $found = $false |
| 84 | + foreach ($effectiveEntry in $effectiveEntries) { |
| 85 | + if (($effectiveEntry.FullName -replace "\\","/") -like $requiredEntry) { |
| 86 | + $found = $true |
| 87 | + } |
| 88 | + } |
| 89 | + if (!$found) { |
| 90 | + Write-Warning "Required entry '$requiredEntry' not found or empty" |
| 91 | + $validPackage = $false |
| 92 | + } |
| 93 | + } |
| 94 | + |
| 95 | + # retrun package vaility |
| 96 | + return $validPackage |
| 97 | +} |
0 commit comments