Skip to content

Commit 9444ee9

Browse files
authored
Improve Microsoft Graph module installation in AAD cleanup job (#5322)
* refactor: streamline Microsoft Graph module installation in cleanup job * fix: update Microsoft Graph module installation to use variable for version
1 parent d22b7ef commit 9444ee9

1 file changed

Lines changed: 20 additions & 9 deletions

File tree

build/jobs/cleanup-aad.yml

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,25 @@ jobs:
1818
azurePowerShellVersion: latestVersion
1919
ScriptType: InlineScript
2020
Inline: |
21-
# Install only required Microsoft Graph modules for better performance
22-
# Pin to version 2.33.0 due to bug in 2.34.0 affecting PowerShell 5.1
23-
# See: https://github.com/microsoftgraph/msgraph-sdk-powershell/issues/3479
24-
Install-Module -Name Microsoft.Graph.Authentication -RequiredVersion 2.33.0 -Force
25-
Install-Module -Name Microsoft.Graph.Applications -RequiredVersion 2.33.0 -Force
26-
Install-Module -Name Microsoft.Graph.Users -RequiredVersion 2.33.0 -Force
27-
Install-Module -Name Microsoft.Graph.Identity.DirectoryManagement -RequiredVersion 2.33.0 -Force
28-
21+
# Install and import required Microsoft Graph modules (2.33.0 is the last stable version for PS 5.1 hosted agents)
22+
$graphModuleVersion = '2.33.0'
23+
$graphModules = @(
24+
'Microsoft.Graph.Authentication',
25+
'Microsoft.Graph.Applications',
26+
'Microsoft.Graph.Users',
27+
'Microsoft.Graph.Identity.DirectoryManagement'
28+
)
29+
30+
foreach ($module in $graphModules) {
31+
$installed = Get-Module -ListAvailable -Name $module | Where-Object { $_.Version -eq [version]$graphModuleVersion }
32+
33+
if (-not $installed) {
34+
Install-Module -Name $module -RequiredVersion $graphModuleVersion -Scope CurrentUser -Force -AllowClobber
35+
}
36+
37+
Import-Module -Name $module -ErrorAction Stop
38+
}
39+
2940
$username = "$(tenant-admin-user-name)"
3041
$clientId = "$(tenant-admin-service-principal-name)"
3142
$clientSecret = "$(tenant-admin-service-principal-password)"
@@ -36,7 +47,7 @@ jobs:
3647
$clientSecretCredential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $clientId, $clientSecret_secure
3748
3849
# Connect to Microsoft Graph using client credentials
39-
Connect-MgGraph -TenantId $tenantId -ClientSecretCredential $clientSecretCredential
50+
Connect-MgGraph -TenantId $tenantId -ClientSecretCredential $clientSecretCredential -NoWelcome
4051
4152
Import-Module $(System.DefaultWorkingDirectory)/samples/scripts/PowerShell/FhirServer/FhirServer.psd1
4253
Import-Module $(System.DefaultWorkingDirectory)/release/scripts/PowerShell/FhirServerRelease/FhirServerRelease.psd1

0 commit comments

Comments
 (0)