Skip to content

Commit

Permalink
Bug fixes (#69)
Browse files Browse the repository at this point in the history
* Add progress bar activity for packaging

* Hide error when resource is not found

* Fix format-csv

* Add guidance when data collection fails

* Fix null members error
  • Loading branch information
jazuntee authored Sep 9, 2022
1 parent 6e0f021 commit a3ecdcf
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 35 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ Invoke-AADAssessmentHybridDataCollection

The output package will be named according to the following pattern: `AzureADAssessmentData-<TenantDomain>.aad`

If Data Collection command fails before completing, try running it again with the SkipReportOutput parameter.
```PowerShell
Invoke-AADAssessmentDataCollection -SkipReportOutput
```

Once data collection is complete, provide the output packages to whoever is completing the assessment. Please avoid making any changes to the generated files including the name of the file.

## Complete Assessment Reports
Expand Down
2 changes: 1 addition & 1 deletion src/Get-AADAssessUserReport.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ function Get-AADAssessUserReport {
"onPremisesSyncEnabled" = [bool]$_.onPremisesSyncEnabled
"onPremisesImmutableId" = ![string]::IsNullOrWhiteSpace($InputObject.onPremisesImmutableId)
"mail" = $InputObject.mail
"otherMails" = $InputObject.otherMails -join ';'
"otherMails" = $InputObject.otherMails
"AADLicense" = $aadLicense
"lastInteractiveSignInDateTime" = $lastInteractiveSignInDateTime
"lastNonInteractiveSignInDateTime" = $lastNonInteractiveSignInDateTime
Expand Down
32 changes: 17 additions & 15 deletions src/Invoke-AADAssessmentDataCollection.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,23 @@ function Invoke-AADAssessmentDataCollection {
Remove-Item -Path (Join-Path $OutputDirectoryAAD "*") -Include "*Data.csv" -ErrorAction Ignore
}

### Package Output
if (!$SkipPackaging) {
Write-AppInsightsTrace ("{0} - Package Output" -f $MyInvocation.MyCommand.Name) -SeverityLevel Verbose -IncludeProcessStatistics -OrderedProperties (Get-ReferencedIdCacheDetail $ReferencedIdCache)
Write-Progress -Id 0 -Activity ('Microsoft Azure AD Assessment - {0}' -f $InitialTenantDomain) -Status 'Packaging Data' -PercentComplete 95

### Remove pre existing package (zip) if it exists
if (Test-Path -Path $PackagePath) { Remove-Item $PackagePath -Force }

### Package Output
#Compress-Archive (Join-Path $OutputDirectoryData '\*') -DestinationPath $PackagePath -Force -ErrorAction Stop
[System.IO.Compression.ZipFile]::CreateFromDirectory($OutputDirectoryData, $PackagePath)
$PackageFileInfo = Get-Item $PackagePath
Write-AppInsightsTrace ("{0} - Package Complete" -f $MyInvocation.MyCommand.Name) -SeverityLevel Verbose -IncludeProcessStatistics -OrderedProperties ((Get-ReferencedIdCacheDetail $ReferencedIdCache) + [ordered]@{ PackageSize = Format-NumberWithUnit $PackageFileInfo.Length 'B'; PackageSizeInBytes = $PackageFileInfo.Length })

Remove-Item $OutputDirectoryData -Recurse -Force
}

### Complete
Write-Progress -Id 0 -Activity ('Microsoft Azure AD Assessment - {0}' -f $InitialTenantDomain) -Completed

Expand All @@ -372,21 +389,6 @@ function Invoke-AADAssessmentDataCollection {
#Stop-Transcript
#$Error | Select-Object -Last ($Error.Count - $ErrorStartCount) | Export-Clixml -Path (Join-Path $OutputDirectoryData "PowerShell_errors.xml") -Depth 10

if (!$SkipPackaging) {
Write-AppInsightsTrace ("{0} - Package" -f $MyInvocation.MyCommand.Name) -SeverityLevel Verbose -IncludeProcessStatistics -OrderedProperties (Get-ReferencedIdCacheDetail $ReferencedIdCache)

### Remove pre existing package (zip) if it exists
if (Test-Path -Path $PackagePath) {
Remove-Item $PackagePath -Force
}

### Package Output
#Compress-Archive (Join-Path $OutputDirectoryData '\*') -DestinationPath $PackagePath -Force -ErrorAction Stop
[System.IO.Compression.ZipFile]::CreateFromDirectory($OutputDirectoryData,$PackagePath)

Remove-Item $OutputDirectoryData -Recurse -Force
}

### Open Directory
try {
Invoke-Item $OutputDirectory -ErrorAction SilentlyContinue
Expand Down
28 changes: 15 additions & 13 deletions src/internal/Expand-GroupTransitiveMembership.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,21 @@ function Expand-GroupTransitiveMembership {
if ($Group.psobject.Properties.Name.Contains('transitiveMembers')) { $Group.transitiveMembers }
else {
$transitiveMembers = New-Object 'System.Collections.Generic.Dictionary[guid,psobject]'
foreach ($member in $Group.members) {
if (!$transitiveMembers.ContainsKey($member.id)) {
$transitiveMembers.Add($member.id, $member)
$member
}
if ($member.'@odata.type' -eq '#microsoft.graph.group') {
if (!$GroupId.Contains($member.id)) {
$GroupId.Push($member.id)
$transitiveMembersNested = Expand-GroupTransitiveMembership $GroupId -LookupCache $LookupCache
foreach ($memberNested in $transitiveMembersNested) {
if (!$transitiveMembers.ContainsKey($memberNested.id)) {
$transitiveMembers.Add($memberNested.id, $memberNested)
$memberNested
if ($Group.psobject.Properties.Name.Contains('members')) {
foreach ($member in $Group.members) {
if (!$transitiveMembers.ContainsKey($member.id)) {
$transitiveMembers.Add($member.id, $member)
$member
}
if ($member.'@odata.type' -eq '#microsoft.graph.group') {
if (!$GroupId.Contains($member.id)) {
$GroupId.Push($member.id)
$transitiveMembersNested = Expand-GroupTransitiveMembership $GroupId -LookupCache $LookupCache
foreach ($memberNested in $transitiveMembersNested) {
if (!$transitiveMembers.ContainsKey($memberNested.id)) {
$transitiveMembers.Add($memberNested.id, $memberNested)
$memberNested
}
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/internal/Format-Csv.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,22 @@ function Format-Csv {
[psobject[]] $InputObjects,
#
[Parameter(Mandatory = $false)]
[string] $ArrayDelimiter = "`r`n"
[string] $ArrayDelimiter = ";"
)

begin {
function Transform ($InputObject) {
if ($InputObject) {
if ($Property.Value -is [DateTime]) {
if ($InputObject -is [DateTime]) {
$InputObject = $InputObject.ToString("o")
}
elseif ($Property.Value -is [Array] -or $Property.Value -is [System.Collections.ArrayList]) {
elseif ($InputObject -is [Array] -or $InputObject -is [System.Collections.ArrayList]) {
for ($i = 0; $i -lt $InputObject.Count; $i++) {
$InputObject[$i] = Transform $InputObject[$i]
}
$InputObject = $InputObject -join $ArrayDelimiter
}
elseif ($Property.Value -is [System.Management.Automation.PSCustomObject]) {
elseif ($InputObject -is [System.Management.Automation.PSCustomObject]) {
return ConvertTo-Json $InputObject
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/internal/Get-MsGraphResults.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ function Get-MsGraphResults {
else {
## Ignore errors with specific codes else display non-terminating error
if ($ResponseDetail['ContentParsed'].error.code -eq 'Request_ResourceNotFound') {
Write-Error -Exception $_.Exception -Message $ResponseDetail['ContentParsed'].error.message -ErrorId $ResponseDetail['ContentParsed'].error.code -Category $_.CategoryInfo.Category -CategoryActivity $_.CategoryInfo.Activity -CategoryReason $_.CategoryInfo.Reason -CategoryTargetName $_.CategoryInfo.TargetName -CategoryTargetType $_.CategoryInfo.TargetType -TargetObject $_.TargetObject -ErrorVariable cmdError -ErrorAction SilentlyContinue
#Write-Error -Exception $_.Exception -Message $ResponseDetail['ContentParsed'].error.message -ErrorId $ResponseDetail['ContentParsed'].error.code -Category $_.CategoryInfo.Category -CategoryActivity $_.CategoryInfo.Activity -CategoryReason $_.CategoryInfo.Reason -CategoryTargetName $_.CategoryInfo.TargetName -CategoryTargetType $_.CategoryInfo.TargetType -TargetObject $_.TargetObject -ErrorVariable cmdError -ErrorAction SilentlyContinue
#Write-Warning $ResponseDetail['ContentParsed'].error.message
}
else {
Expand All @@ -158,7 +158,7 @@ function Get-MsGraphResults {
else {
## Ignore errors with specific codes else display non-terminating error
if ($BatchResponse.body.error.code -eq 'Request_ResourceNotFound') {
Write-Error -Message $BatchResponse.body.error.message -ErrorId $BatchResponse.body.error.code -ErrorVariable cmdError -ErrorAction SilentlyContinue
#Write-Error -Message $BatchResponse.body.error.message -ErrorId $BatchResponse.body.error.code -ErrorVariable cmdError -ErrorAction SilentlyContinue
#Write-Warning $BatchResponse.body.error.message
}
else {
Expand Down

0 comments on commit a3ecdcf

Please sign in to comment.