Skip to content

Commit a3ecdcf

Browse files
authored
Bug fixes (#69)
* 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
1 parent 6e0f021 commit a3ecdcf

6 files changed

+44
-35
lines changed

README.md

+5
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ Invoke-AADAssessmentHybridDataCollection
4444

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

47+
If Data Collection command fails before completing, try running it again with the SkipReportOutput parameter.
48+
```PowerShell
49+
Invoke-AADAssessmentDataCollection -SkipReportOutput
50+
```
51+
4752
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.
4853

4954
## Complete Assessment Reports

src/Get-AADAssessUserReport.ps1

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ function Get-AADAssessUserReport {
7979
"onPremisesSyncEnabled" = [bool]$_.onPremisesSyncEnabled
8080
"onPremisesImmutableId" = ![string]::IsNullOrWhiteSpace($InputObject.onPremisesImmutableId)
8181
"mail" = $InputObject.mail
82-
"otherMails" = $InputObject.otherMails -join ';'
82+
"otherMails" = $InputObject.otherMails
8383
"AADLicense" = $aadLicense
8484
"lastInteractiveSignInDateTime" = $lastInteractiveSignInDateTime
8585
"lastNonInteractiveSignInDateTime" = $lastNonInteractiveSignInDateTime

src/Invoke-AADAssessmentDataCollection.ps1

+17-15
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,23 @@ function Invoke-AADAssessmentDataCollection {
358358
Remove-Item -Path (Join-Path $OutputDirectoryAAD "*") -Include "*Data.csv" -ErrorAction Ignore
359359
}
360360

361+
### Package Output
362+
if (!$SkipPackaging) {
363+
Write-AppInsightsTrace ("{0} - Package Output" -f $MyInvocation.MyCommand.Name) -SeverityLevel Verbose -IncludeProcessStatistics -OrderedProperties (Get-ReferencedIdCacheDetail $ReferencedIdCache)
364+
Write-Progress -Id 0 -Activity ('Microsoft Azure AD Assessment - {0}' -f $InitialTenantDomain) -Status 'Packaging Data' -PercentComplete 95
365+
366+
### Remove pre existing package (zip) if it exists
367+
if (Test-Path -Path $PackagePath) { Remove-Item $PackagePath -Force }
368+
369+
### Package Output
370+
#Compress-Archive (Join-Path $OutputDirectoryData '\*') -DestinationPath $PackagePath -Force -ErrorAction Stop
371+
[System.IO.Compression.ZipFile]::CreateFromDirectory($OutputDirectoryData, $PackagePath)
372+
$PackageFileInfo = Get-Item $PackagePath
373+
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 })
374+
375+
Remove-Item $OutputDirectoryData -Recurse -Force
376+
}
377+
361378
### Complete
362379
Write-Progress -Id 0 -Activity ('Microsoft Azure AD Assessment - {0}' -f $InitialTenantDomain) -Completed
363380

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

375-
if (!$SkipPackaging) {
376-
Write-AppInsightsTrace ("{0} - Package" -f $MyInvocation.MyCommand.Name) -SeverityLevel Verbose -IncludeProcessStatistics -OrderedProperties (Get-ReferencedIdCacheDetail $ReferencedIdCache)
377-
378-
### Remove pre existing package (zip) if it exists
379-
if (Test-Path -Path $PackagePath) {
380-
Remove-Item $PackagePath -Force
381-
}
382-
383-
### Package Output
384-
#Compress-Archive (Join-Path $OutputDirectoryData '\*') -DestinationPath $PackagePath -Force -ErrorAction Stop
385-
[System.IO.Compression.ZipFile]::CreateFromDirectory($OutputDirectoryData,$PackagePath)
386-
387-
Remove-Item $OutputDirectoryData -Recurse -Force
388-
}
389-
390392
### Open Directory
391393
try {
392394
Invoke-Item $OutputDirectory -ErrorAction SilentlyContinue

src/internal/Expand-GroupTransitiveMembership.ps1

+15-13
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,21 @@ function Expand-GroupTransitiveMembership {
2222
if ($Group.psobject.Properties.Name.Contains('transitiveMembers')) { $Group.transitiveMembers }
2323
else {
2424
$transitiveMembers = New-Object 'System.Collections.Generic.Dictionary[guid,psobject]'
25-
foreach ($member in $Group.members) {
26-
if (!$transitiveMembers.ContainsKey($member.id)) {
27-
$transitiveMembers.Add($member.id, $member)
28-
$member
29-
}
30-
if ($member.'@odata.type' -eq '#microsoft.graph.group') {
31-
if (!$GroupId.Contains($member.id)) {
32-
$GroupId.Push($member.id)
33-
$transitiveMembersNested = Expand-GroupTransitiveMembership $GroupId -LookupCache $LookupCache
34-
foreach ($memberNested in $transitiveMembersNested) {
35-
if (!$transitiveMembers.ContainsKey($memberNested.id)) {
36-
$transitiveMembers.Add($memberNested.id, $memberNested)
37-
$memberNested
25+
if ($Group.psobject.Properties.Name.Contains('members')) {
26+
foreach ($member in $Group.members) {
27+
if (!$transitiveMembers.ContainsKey($member.id)) {
28+
$transitiveMembers.Add($member.id, $member)
29+
$member
30+
}
31+
if ($member.'@odata.type' -eq '#microsoft.graph.group') {
32+
if (!$GroupId.Contains($member.id)) {
33+
$GroupId.Push($member.id)
34+
$transitiveMembersNested = Expand-GroupTransitiveMembership $GroupId -LookupCache $LookupCache
35+
foreach ($memberNested in $transitiveMembersNested) {
36+
if (!$transitiveMembers.ContainsKey($memberNested.id)) {
37+
$transitiveMembers.Add($memberNested.id, $memberNested)
38+
$memberNested
39+
}
3840
}
3941
}
4042
}

src/internal/Format-Csv.ps1

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,22 @@ function Format-Csv {
88
[psobject[]] $InputObjects,
99
#
1010
[Parameter(Mandatory = $false)]
11-
[string] $ArrayDelimiter = "`r`n"
11+
[string] $ArrayDelimiter = ";"
1212
)
1313

1414
begin {
1515
function Transform ($InputObject) {
1616
if ($InputObject) {
17-
if ($Property.Value -is [DateTime]) {
17+
if ($InputObject -is [DateTime]) {
1818
$InputObject = $InputObject.ToString("o")
1919
}
20-
elseif ($Property.Value -is [Array] -or $Property.Value -is [System.Collections.ArrayList]) {
20+
elseif ($InputObject -is [Array] -or $InputObject -is [System.Collections.ArrayList]) {
2121
for ($i = 0; $i -lt $InputObject.Count; $i++) {
2222
$InputObject[$i] = Transform $InputObject[$i]
2323
}
2424
$InputObject = $InputObject -join $ArrayDelimiter
2525
}
26-
elseif ($Property.Value -is [System.Management.Automation.PSCustomObject]) {
26+
elseif ($InputObject -is [System.Management.Automation.PSCustomObject]) {
2727
return ConvertTo-Json $InputObject
2828
}
2929
}

src/internal/Get-MsGraphResults.ps1

+2-2
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ function Get-MsGraphResults {
133133
else {
134134
## Ignore errors with specific codes else display non-terminating error
135135
if ($ResponseDetail['ContentParsed'].error.code -eq 'Request_ResourceNotFound') {
136-
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
136+
#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
137137
#Write-Warning $ResponseDetail['ContentParsed'].error.message
138138
}
139139
else {
@@ -158,7 +158,7 @@ function Get-MsGraphResults {
158158
else {
159159
## Ignore errors with specific codes else display non-terminating error
160160
if ($BatchResponse.body.error.code -eq 'Request_ResourceNotFound') {
161-
Write-Error -Message $BatchResponse.body.error.message -ErrorId $BatchResponse.body.error.code -ErrorVariable cmdError -ErrorAction SilentlyContinue
161+
#Write-Error -Message $BatchResponse.body.error.message -ErrorId $BatchResponse.body.error.code -ErrorVariable cmdError -ErrorAction SilentlyContinue
162162
#Write-Warning $BatchResponse.body.error.message
163163
}
164164
else {

0 commit comments

Comments
 (0)