Skip to content

Commit e8eef7d

Browse files
authored
Bug fixes, performance, and reliability improvements (#65)
* update role assignment collection logic * Update pbit to match pwsh output * Fix module version check * Fix bug on tenants with no P2 licenses * Fix warning on tenants with no AAD licenses * Remove resource not found warnings * Remove auth method registration warning * Remove posh test gallery from cd pipeline * Stop auto trigger of CD pipeline on preview branch * Test break on error * Add ScriptStackTrace to exception telemetry * Add data to exception telemetry * Remove old comments * update ms graph batching and telemetry * update mg calls to v1.0 and general clean up * Add ordereddictionary param to all appinsight func * Fix error when run as different user * Move scopes definition to module variable * Add comments and fix error retry * Add warning to upgrade PowerShell version * Remove WinPoSh warning until device comp support * Additional telemetry for troubleshooting * Add retry for Timeout exception * Fix relative uri code path * limit downloading membership of large groups * Fix RequiredAssemblies on publish, find type error * Update retry logic and progress bar text * shorten progress bar activity text * fix assignedPlans filter * move zip assembly load from manifest to script
1 parent 444dc53 commit e8eef7d

33 files changed

+743
-247
lines changed

build/Launch-PSModule.ps1

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ param
1818
)
1919

2020
if ($NoNewWindow) {
21+
#$ErrorActionPreference = [System.Management.Automation.ActionPreference]::Break
2122
Import-Module $ModuleManifestPath -PassThru -Force
2223
if ($PostImportScriptBlock) { Invoke-Command -ScriptBlock $PostImportScriptBlock -NoNewScope }
2324
}
@@ -26,6 +27,7 @@ else {
2627
param ([string]$ModulePath, [scriptblock]$PostImportScriptBlock)
2728
## Force WindowsPowerShell to load correct version of built-in modules when launched from PowerShell 6+
2829
if ($PSVersionTable.PSEdition -eq 'Desktop') { Import-Module 'Microsoft.PowerShell.Management', 'Microsoft.PowerShell.Utility', 'CimCmdlets' -MaximumVersion 5.9.9.9 }
30+
#$ErrorActionPreference = [System.Management.Automation.ActionPreference]::Break
2931
Import-Module $ModulePath -PassThru -ArgumentList @{
3032
'ai.instrumentationKey' = 'f7c43a96-9493-41e3-ad62-4320f5835ce2'
3133
}

build/Update-PSModuleManifest.ps1

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,23 @@ param
1212
# Indicates the module is prerelease.
1313
[Parameter(Mandatory = $false)]
1414
[string] $Prerelease,
15-
# Skip Update of RequiredAssemblies
15+
# Skip automatic additions to RequiredAssemblies from module file list.
1616
[Parameter(Mandatory = $false)]
17-
[switch] $SkipRequiredAssemblies
17+
[switch] $SkipRequiredAssembliesDetection
1818
)
1919

2020
## Initialize
2121
Import-Module "$PSScriptRoot\CommonFunctions.psm1" -Force -WarningAction SilentlyContinue -ErrorAction Stop
2222
[hashtable] $paramUpdateModuleManifest = @{ }
2323
if ($Guid) { $paramUpdateModuleManifest['Guid'] = $Guid }
2424
if ($ModuleVersion) { $paramUpdateModuleManifest['ModuleVersion'] = $ModuleVersion }
25-
if ($Prerelease) { $paramUpdateModuleManifest['Prerelease'] = $Prerelease }
2625

2726
[System.IO.FileInfo] $ModuleManifestFileInfo = Get-PathInfo $ModuleManifestPath -DefaultFilename "*.psd1" -ErrorAction Stop
2827

2928
## Read Module Manifest
3029
$ModuleManifest = Import-PowerShellDataFile $ModuleManifestFileInfo.FullName
30+
if ($ModuleManifest.PrivateData.PSData['Prerelease'] -eq 'source') { $paramUpdateModuleManifest['Prerelease'] = "" }
31+
if ($Prerelease) { $paramUpdateModuleManifest['Prerelease'] = $Prerelease }
3132
if ($ModuleManifest.NestedModules) { $paramUpdateModuleManifest['NestedModules'] = $ModuleManifest.NestedModules }
3233
$paramUpdateModuleManifest['FunctionsToExport'] = $ModuleManifest.FunctionsToExport
3334
$paramUpdateModuleManifest['CmdletsToExport'] = $ModuleManifest.CmdletsToExport
@@ -43,10 +44,13 @@ $ModuleFileList = Get-RelativePath $ModuleFileListFileInfo.FullName -WorkingDire
4344
$ModuleFileList = $ModuleFileList -replace '\\net45\\', '\!!!\' -replace '\\netcoreapp2.1\\', '\net45\' -replace '\\!!!\\', '\netcoreapp2.1\' # PowerShell Core fails to load assembly if net45 dll comes before netcoreapp2.1 dll in the FileList.
4445
$paramUpdateModuleManifest['FileList'] = $ModuleFileList
4546

46-
if (!$SkipRequiredAssemblies -and $ModuleRequiredAssembliesFileInfo) {
47+
## Generate RequiredAssemblies list based on existing items and file list
48+
$paramUpdateModuleManifest['RequiredAssemblies'] += $ModuleManifest.RequiredAssemblies | Where-Object { $_ -notin $ModuleFileListFileInfo.Name }
49+
if (!$SkipRequiredAssembliesDetection -and $ModuleRequiredAssembliesFileInfo) {
4750
$ModuleRequiredAssemblies = Get-RelativePath $ModuleRequiredAssembliesFileInfo.FullName -WorkingDirectory $ModuleOutputDirectoryInfo.FullName -ErrorAction Stop
48-
$paramUpdateModuleManifest['RequiredAssemblies'] = $ModuleRequiredAssemblies
51+
$paramUpdateModuleManifest['RequiredAssemblies'] += $ModuleRequiredAssemblies
4952
}
53+
if (!$paramUpdateModuleManifest['RequiredAssemblies']) { $paramUpdateModuleManifest.Remove('RequiredAssemblies') }
5054

5155
## Clear RequiredAssemblies
5256
(Get-Content $ModuleManifestFileInfo.FullName -Raw) -replace "(?s)RequiredAssemblies\ =\ @\([^)]*\)", "# RequiredAssemblies = @()" | Set-Content $ModuleManifestFileInfo.FullName

build/azure-pipelines/azure-pipelines-cd.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ resources:
99
branches:
1010
include:
1111
- master
12-
- preview
12+
#- preview
1313

1414
parameters:
1515
- name: vmImage

build/azure-pipelines/template-psmodule-build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ steps:
8181
displayName: 'Update PowerShell Module Manifest'
8282
inputs:
8383
filePath: '$(System.DefaultWorkingDirectory)/build/Update-PSModuleManifest.ps1'
84-
arguments: '-ModuleManifestPath "$(Pipeline.Workspace)/${{ parameters.artifactOutput }}/${{ coalesce(parameters.moduleRename,parameters.moduleName) }}/${{ coalesce(parameters.moduleRename,parameters.moduleName) }}.psd1" -Guid "${{ parameters.moduleGuid }}" -ModuleVersion "${{ parameters.moduleVersion }}" -Prerelease "${{ parameters.prereleaseTag }}" -SkipRequiredAssemblies'
84+
arguments: '-ModuleManifestPath "$(Pipeline.Workspace)/${{ parameters.artifactOutput }}/${{ coalesce(parameters.moduleRename,parameters.moduleName) }}/${{ coalesce(parameters.moduleRename,parameters.moduleName) }}.psd1" -Guid "${{ parameters.moduleGuid }}" -ModuleVersion "${{ parameters.moduleVersion }}" -Prerelease "${{ parameters.prereleaseTag }}"'
8585
pwsh: true
8686

8787
- ${{ if parameters.GenerateManifest }}:

src/AzureADAssessment.psd1

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ RequiredModules = @(
5656
)
5757

5858
# Assemblies that must be loaded prior to importing this module
59-
RequiredAssemblies = @("System.IO.Compression.FileSystem.dll")
59+
# RequiredAssemblies = @()
6060

6161
# Script files (.ps1) that are run in the caller's environment prior to importing this module.
6262
# ScriptsToProcess = @()
@@ -86,6 +86,7 @@ NestedModules = @(
8686
'.\internal\Export-JsonArray.ps1'
8787
'.\internal\Get-MsGraphResults.ps1'
8888
'.\internal\Format-Csv.ps1'
89+
'.\internal\Format-NumberWithUnit.ps1'
8990
'.\internal\Get-AadObjectById.ps1'
9091
'.\internal\Get-ObjectPropertyValue.ps1'
9192
'.\internal\Get-SpreadsheetJson.ps1'
@@ -179,7 +180,7 @@ PrivateData = @{
179180
PSData = @{
180181

181182
# Tags applied to this module. These help with module discovery in online galleries.
182-
Tags = 'Microsoft', 'Identity', 'Azure', 'AzureActiveDirectory', 'AzureAD', 'AAD', 'PSEdition_Desktop', 'PSEdition_Core', 'Windows', 'Linux', 'MacOS'
183+
Tags = 'Microsoft', 'Identity', 'Azure', 'AzureActiveDirectory', 'AzureAD', 'AAD', 'PSEdition_Desktop', 'PSEdition_Core', 'Windows', 'Linux', 'MacOS'
183184

184185
# A URL to the license for this module.
185186
LicenseUri = 'https://raw.githubusercontent.com/AzureAD/AzureADAssessment/master/LICENSE'
@@ -193,6 +194,9 @@ PrivateData = @{
193194
# ReleaseNotes of this module
194195
# ReleaseNotes = ''
195196

197+
# Prerelease string of this module
198+
Prerelease = 'source'
199+
196200
# External dependent modules of this module
197201
# ExternalModuleDependencies = @()
198202

src/AzureADAssessment.psm1

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ param (
1717
## Set Strict Mode for Module. https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/set-strictmode
1818
Set-StrictMode -Version 3.0
1919

20+
## Display Warning on old PowerShell versions. https://docs.microsoft.com/en-us/powershell/scripting/install/PowerShell-Support-Lifecycle#powershell-end-of-support-dates
21+
# ToDo: Only Windows PowerShell can currently satify device compliance CA requirement. Look at adding Windows Broker (WAM) support to support device compliance on PowerShell 7.
22+
# if ($PSVersionTable.PSVersion -lt [version]'7.0') {
23+
# Write-Warning 'It is recommended to use this module with the latest version of PowerShell which can be downloaded here: https://aka.ms/install-powershell'
24+
# }
25+
2026
## Initialize Module Configuration
2127
$script:ModuleConfigDefault = Import-Config -Path (Join-Path $PSScriptRoot 'config.json')
2228
$script:ModuleConfig = $script:ModuleConfigDefault.psobject.Copy()
@@ -25,6 +31,11 @@ Import-Config | Set-Config
2531
if ($PSBoundParameters.ContainsKey('ModuleConfiguration')) { Set-Config $ModuleConfiguration }
2632
#Export-Config
2733

34+
# Load zip dll on Windows PowerShell
35+
if ($PSVersionTable.PSEdition -eq 'Desktop') {
36+
Add-Type -AssemblyName System.IO.Compression.FileSystem -ErrorAction Stop
37+
}
38+
2839
## Initialize Module Variables
2940
$script:ConnectState = @{
3041
ClientApplication = $null
@@ -41,6 +52,20 @@ $script:MsGraphSession.UserAgent += ' AzureADAssessment'
4152
# UseDefaultCredentials = $true
4253
# }
4354

55+
[string[]] $script:MsGraphScopes = @(
56+
'Organization.Read.All'
57+
'RoleManagement.Read.Directory'
58+
'Application.Read.All'
59+
'User.Read.All'
60+
'Group.Read.All'
61+
'Policy.Read.All'
62+
'Directory.Read.All'
63+
'SecurityEvents.Read.All'
64+
'UserAuthenticationMethod.Read.All'
65+
'AuditLog.Read.All'
66+
'Reports.Read.All'
67+
)
68+
4469
$script:mapMgEnvironmentToAzureCloudInstance = @{
4570
'Global' = 'AzurePublic'
4671
'China' = 'AzureChina'

src/AzureADAssessmentPortable.psm1

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,10 @@ function Export-AADAssessADFSConfiguration {
156156
#Add-Type -assembly "system.io.compression.filesystem"
157157
#[io.compression.zipfile]::CreateFromDirectory($filePathBase, $zipfileName)
158158

159-
#Invoke-Item $zipfileBase
159+
# try {
160+
# Invoke-Item $zipfileBase -ErrorAction SilentlyContinue
161+
# }
162+
# catch {}
160163
}
161164

162165

src/Complete-AADAssessmentReports.ps1

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,10 @@ function Complete-AADAssessmentReports {
162162
Assert-DirectoryExists $PowerBIWorkingDirectory
163163
Copy-Item -Path (Join-Path $OutputDirectoryAAD '*') -Destination $PowerBIWorkingDirectory -Force
164164
Copy-Item -LiteralPath $PBITemplateAssessmentPath, $PBITemplateConditionalAccessPath -Destination $PowerBIWorkingDirectory -Force
165-
#Invoke-Item $PowerBIWorkingDirectory
165+
# try {
166+
# Invoke-Item $PowerBIWorkingDirectory -ErrorAction SilentlyContinue
167+
# }
168+
# catch {}
166169
}
167170

168171
## Expand AAD Connect
@@ -171,9 +174,12 @@ function Complete-AADAssessmentReports {
171174

172175
## Complete
173176
Write-Progress -Id 0 -Activity ('Microsoft Azure AD Assessment Complete Reports - {0}' -f $AssessmentDetail.AssessmentTenantDomain) -Completed
174-
Invoke-Item $OutputDirectoryData
177+
try {
178+
Invoke-Item $OutputDirectoryData -ErrorAction SilentlyContinue
179+
}
180+
catch {}
175181

176182
}
177-
catch { if ($MyInvocation.CommandOrigin -eq 'Runspace') { Write-AppInsightsException $_.Exception }; throw }
183+
catch { if ($MyInvocation.CommandOrigin -eq 'Runspace') { Write-AppInsightsException -ErrorRecord $_ -IncludeProcessStatistics }; throw }
178184
finally { Complete-AppInsightsRequest $MyInvocation.MyCommand.Name -Success $? }
179185
}

src/Connect-AADAssessment.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,11 @@ function Connect-AADAssessment {
6363
}
6464
$script:ConnectState.CloudEnvironment = $CloudEnvironment
6565

66-
Confirm-ModuleAuthentication $script:ConnectState.ClientApplication -CloudEnvironment $script:ConnectState.CloudEnvironment -User $User -ErrorAction Stop
66+
Confirm-ModuleAuthentication $script:ConnectState.ClientApplication -CloudEnvironment $script:ConnectState.CloudEnvironment -User $User -CorrelationId $script:AppInsightsRuntimeState.OperationStack.Peek().Id -ErrorAction Stop
6767
#Get-MgContext
6868
#Get-AzureADCurrentSessionInfo
6969
Write-Debug ($script:ConnectState.MsGraphToken.Scopes -join ' ')
7070
}
71-
catch { if ($MyInvocation.CommandOrigin -eq 'Runspace') { Write-AppInsightsException $_.Exception }; throw }
71+
catch { if ($MyInvocation.CommandOrigin -eq 'Runspace') { Write-AppInsightsException -ErrorRecord $_ -IncludeProcessStatistics }; throw }
7272
finally { Complete-AppInsightsRequest $MyInvocation.MyCommand.Name -Success $? }
7373
}

src/Disconnect-AADAssessment.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@ function Disconnect-AADAssessment {
2020
}
2121

2222
}
23-
catch { if ($MyInvocation.CommandOrigin -eq 'Runspace') { Write-AppInsightsException $_.Exception }; throw }
23+
catch { if ($MyInvocation.CommandOrigin -eq 'Runspace') { Write-AppInsightsException -ErrorRecord $_ -IncludeProcessStatistics }; throw }
2424
finally { Complete-AppInsightsRequest $MyInvocation.MyCommand.Name -Success $? }
2525
}

src/Expand-AADAssessAADConnectConfig.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,6 @@ function Expand-AADAssessAADConnectConfig {
7575
Write-Output $report.FullName
7676

7777
}
78-
catch { if ($MyInvocation.CommandOrigin -eq 'Runspace') { Write-AppInsightsException $_.Exception }; throw }
78+
catch { if ($MyInvocation.CommandOrigin -eq 'Runspace') { Write-AppInsightsException -ErrorRecord $_ -IncludeProcessStatistics }; throw }
7979
finally { Complete-AppInsightsRequest $MyInvocation.MyCommand.Name -Success $? }
8080
}

src/Export-AADAssessConditionalAccessData.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,6 @@ function Export-AADAssessConditionalAccessData {
5656
#| Export-JsonArray (Join-Path $OutputDirectory "servicePrincipals.json") -Depth 5 -Compress
5757

5858
}
59-
catch { if ($MyInvocation.CommandOrigin -eq 'Runspace') { Write-AppInsightsException $_.Exception }; throw }
59+
catch { if ($MyInvocation.CommandOrigin -eq 'Runspace') { Write-AppInsightsException -ErrorRecord $_ -IncludeProcessStatistics }; throw }
6060
finally { Complete-AppInsightsRequest $MyInvocation.MyCommand.Name -Success $? }
6161
}

src/Export-AADAssessmentPortableModule.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@ function Export-AADAssessmentPortableModule {
2727
#Invoke-WebRequest -Uri 'https://github.com/AzureAD/Deployment-Plans/raw/master/ADFS%20to%20AzureAD%20App%20Migration/ADFSAADMigrationUtils.psm1' -UseBasicParsing -OutFile $AdfsAadMigrationModulePath
2828

2929
}
30-
catch { if ($MyInvocation.CommandOrigin -eq 'Runspace') { Write-AppInsightsException $_.Exception }; throw }
30+
catch { if ($MyInvocation.CommandOrigin -eq 'Runspace') { Write-AppInsightsException -ErrorRecord $_ -IncludeProcessStatistics }; throw }
3131
finally { Complete-AppInsightsRequest $MyInvocation.MyCommand.Name -Success $? }
3232
}

0 commit comments

Comments
 (0)