Skip to content

Commit 0425b78

Browse files
committed
Fix assessment on gov cloud tenants
1 parent 31e1e66 commit 0425b78

4 files changed

+49
-15
lines changed

README.md

+30-10
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ Invoke-AADAssessmentDataCollection
3838

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

41+
If Data Collection command fails before completing, try running it again with the SkipReportOutput parameter.
42+
43+
```PowerShell
44+
Invoke-AADAssessmentDataCollection -SkipReportOutput
45+
```
46+
4147
On each server running hybrid components, install the same module and run the Invoke-AADAssessmentHybridDataCollection command.
4248
```PowerShell
4349
## Export Data to "C:\AzureADAssessment" into a single output package.
@@ -46,11 +52,6 @@ Invoke-AADAssessmentHybridDataCollection
4652

4753
The output package will be named according to the following pattern: `AzureADAssessmentData-<Svc>-<ServerName>.zip`
4854

49-
If Data Collection command fails before completing, try running it again with the SkipReportOutput parameter.
50-
```PowerShell
51-
Invoke-AADAssessmentDataCollection -SkipReportOutput
52-
```
53-
5455
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.
5556

5657
## Complete Assessment Reports
@@ -73,20 +74,39 @@ Import-Module "C:\AzureADAssessment\AzureADAssessmentPortable.psm1"
7374
Invoke-AADAssessmentHybridDataCollection
7475
```
7576

76-
### I want to use a service principal identity to run the assessment instead of a user identity
77-
```PowerShell
78-
## If you prefer to use your own app registration (service principal) for automation purposes, you may connect using your own ClientId and Certificate like the example below. Your app registration should include Directory.Read.All and Policy.Read.All permissions to MS Graph for a complete assessment. Once added, ensure you have completed admin consent on the service principal for those application permissions.
79-
Connect-AADAssessment -ClientId <ClientId> -ClientCertificate (Get-Item 'Cert:\CurrentUser\My\<Thumbprint>') -TenantId <TenantId>
77+
### I want to output the assessment files to a different directory
8078

79+
```PowerShell
8180
## If you would like to specify a different directory, use the OutputDirectory parameter.
8281
Invoke-AADAssessmentDataCollection "C:\Temp"
8382
Invoke-AADAssessmentHybridDataCollection "C:\Temp"
8483
```
8584

85+
### I want to use a service principal identity to run the assessment instead of a user identity
86+
If you prefer to use your own app registration (service principal) for automation purposes, you may connect using your own ClientId and Certificate like the example below. Your app registration should include Directory.Read.All and Policy.Read.All permissions to MS Graph for a complete assessment. Once added, ensure you have completed admin consent on the service principal for those application permissions.
87+
```PowerShell
88+
## Connect using Service Principal identity with app permissions.
89+
Connect-AADAssessment -ClientId <ClientId> -ClientCertificate (Get-Item 'Cert:\CurrentUser\My\<Thumbprint>') -TenantId <TenantId>
90+
```
91+
92+
### I have a tenant in sovereign cloud, how do I run this assessment?
93+
You must create an application registration in your tenant and provide the ClientId when running Connect-AADAssessment. The default application configuration should work as long as you define the correct redirect URI for your cloud environment. For example, a "Mobile and desktop application" Redirect URI of `https://login.microsoftonline.us/common/oauth2/nativeclient`.
94+
```PowerShell
95+
## Example connecting to USGov cloud environment using user delegated permissions.
96+
Connect-AADAssessment -ClientId <ClientId> -CloudEnvironment USGov -TenantId <TenantId>
97+
98+
## Example connecting to USGov cloud environment using app permissions.
99+
Connect-AADAssessment -ClientId <ClientId> -ClientCertificate (Get-Item 'Cert:\CurrentUser\My\<Thumbprint>') -CloudEnvironment USGov -TenantId <TenantId>
100+
```
101+
86102
### When trying to install the module I'm receiving the error 'A parameter cannot be found that matches parameter name 'AcceptLicense'
87-
Run the following command to update PowerShellGet to the latest version before attempting to install the AzureADAssessment module again.
103+
Run the following command to update PowerShellGet to the latest version before attempting to install the AzureADAssessment module again. Option 1 is a single command executing a script (<https://aka.ms/Update-PowerShellGet>), while option 2 requires multiple commands and some possible troubleshooting.
88104

89105
```PowerShell
106+
### Option 1: Run the following command to download and execute a script to update PowerShellGet. Note: Navigate to this URL in a web browser to see the contents of the script in GitHub.
107+
iex $(irm 'https://aka.ms/Update-PowerShellGet')
108+
109+
### Option 2: Run the following commands individually.
90110
## Update Nuget Package and PowerShellGet Module
91111
Install-PackageProvider NuGet -Scope CurrentUser -Force
92112
Install-Module PowerShellGet -Scope CurrentUser -Force -AllowClobber

src/AzureADAssessment.psm1

+2-2
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ $script:mapMgEnvironmentToAadRedirectUri = @{
8484
'Global' = 'https://login.microsoftonline.com/common/oauth2/nativeclient'
8585
'China' = 'https://login.partner.microsoftonline.cn/common/oauth2/nativeclient'
8686
'Germany' = 'https://login.microsoftonline.com/common/oauth2/nativeclient'
87-
'USGov' = 'https://login.microsoftonline.com/common/oauth2/nativeclient' #'https://login.microsoftonline.us/common/oauth2/nativeclient'
88-
'USGovDoD' = 'https://login.microsoftonline.com/common/oauth2/nativeclient' #'https://login.microsoftonline.us/common/oauth2/nativeclient'
87+
'USGov' = 'https://login.microsoftonline.us/common/oauth2/nativeclient'
88+
'USGovDoD' = 'https://login.microsoftonline.us/common/oauth2/nativeclient'
8989
}
9090
$script:mapMgEnvironmentToMgEndpoint = @{
9191
'Global' = 'https://graph.microsoft.com/'

src/Connect-AADAssessment.ps1

+5
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ function Connect-AADAssessment {
4343
Start-AppInsightsRequest $MyInvocation.MyCommand.Name
4444
try {
4545

46+
## Parameter Validation
47+
if ($CloudEnvironment -ne 'Global' -and $ClientId -eq $script:ModuleConfig.'aad.clientId') {
48+
Write-Error -Exception (New-Object System.ArgumentException -ArgumentList "Connecting to Cloud Environment [$CloudEnvironment] requires a ClientId to be specified for an application in your tenant.") -ErrorId 'ClientIdParameterRequired' -Category InvalidArgument -ErrorAction Stop
49+
}
50+
4651
## Update WebSession User Agent String with Module Info
4752
$script:MsGraphSession.UserAgent = $script:MsGraphSession.UserAgent -replace 'AzureADAssessment(/[0-9.]*)?', ('{0}/{1}' -f $PSCmdlet.MyInvocation.MyCommand.Module.Name, $MyInvocation.MyCommand.Module.Version)
4853

src/Invoke-AADAssessmentDataCollection.ps1

+12-3
Original file line numberDiff line numberDiff line change
@@ -183,9 +183,18 @@ function Invoke-AADAssessmentDataCollection {
183183
### Directory Role Assignments - 7
184184
Write-AppInsightsTrace ("{0} - Directory Role Assignments" -f $MyInvocation.MyCommand.Name) -SeverityLevel Verbose -IncludeProcessStatistics -OrderedProperties (Get-ReferencedIdCacheDetail $ReferencedIdCache)
185185
Write-Progress -Id 0 -Activity ('Microsoft Azure AD Assessment - {0}' -f $InitialTenantDomain) -Status 'Directory Role Assignments' -PercentComplete 30
186-
Get-MsGraphResults 'roleManagement/directory/roleAssignments' -Select 'id,directoryScopeId,principalId' -QueryParameters @{ '$expand' = 'roleDefinition($select=id,templateId,displayName)' } `
187-
| Add-AadReferencesToCache -Type roleAssignments -ReferencedIdCache $ReferencedIdCache -PassThru `
188-
| Export-Clixml -Path (Join-Path $OutputDirectoryAAD "roleAssignmentsData.xml")
186+
187+
if ($script:ConnectState.CloudEnvironment -in 'USGov', 'USGovDoD') {
188+
## MS Graph endpoint roleManagement/directory/roleAssignments must still have filter on Gov tenants
189+
$roleDefinitions | Get-MsGraphResults 'roleManagement/directory/roleAssignments' -Select 'id,directoryScopeId,principalId' -Filter "roleDefinitionId eq '{0}'" -QueryParameters @{ '$expand' = 'roleDefinition($select=id,templateId,displayName)' } `
190+
| Add-AadReferencesToCache -Type roleAssignments -ReferencedIdCache $ReferencedIdCache -PassThru `
191+
| Export-Clixml -Path (Join-Path $OutputDirectoryAAD "roleAssignmentsData.xml")
192+
}
193+
else {
194+
Get-MsGraphResults 'roleManagement/directory/roleAssignments' -Select 'id,directoryScopeId,principalId' -QueryParameters @{ '$expand' = 'roleDefinition($select=id,templateId,displayName)' } `
195+
| Add-AadReferencesToCache -Type roleAssignments -ReferencedIdCache $ReferencedIdCache -PassThru `
196+
| Export-Clixml -Path (Join-Path $OutputDirectoryAAD "roleAssignmentsData.xml")
197+
}
189198
}
190199
Remove-Variable roleDefinitions
191200

0 commit comments

Comments
 (0)