diff --git a/linux/powershell/setupPowerShell.ps1 b/linux/powershell/setupPowerShell.ps1 index cb123f2..5ca9732 100644 --- a/linux/powershell/setupPowerShell.ps1 +++ b/linux/powershell/setupPowerShell.ps1 @@ -115,7 +115,7 @@ try { PowerShellGet\Install-Module -Name Microsoft.Graph.Identity.DirectoryManagement @prodAllUsers PowerShellGet\Install-Module -Name Microsoft.Graph.Identity.Governance @prodAllUsers PowerShellGet\Install-Module -Name Microsoft.Graph.Identity.SignIns @prodAllUsers - PowerShellGet\Install-Module -Name Microsoft.Graph.Applications @prodAllUsers + PowerShellGet\Install-Module -Name Microsoft.Graph.Applications -RequiredVersion 2.28.0 @prodAllUsers } else { diff --git a/test_graph_modules.ps1 b/test_graph_modules.ps1 new file mode 100644 index 0000000..cf16783 --- /dev/null +++ b/test_graph_modules.ps1 @@ -0,0 +1,21 @@ +Import-Module Microsoft.Graph.Applications -Force -ErrorAction Stop +Import-Module Microsoft.Graph.Groups -Force -ErrorAction Stop + +# Verify modules were loaded successfully +$appsModule = Get-Module Microsoft.Graph.Applications +$groupsModule = Get-Module Microsoft.Graph.Groups +$authModule = Get-Module Microsoft.Graph.Authentication + +Write-Host "Microsoft.Graph.Authentication version: $($authModule.Version.ToString())" +Write-Host "Microsoft.Graph.Applications version: $($appsModule.Version.ToString())" +Write-Host "Microsoft.Graph.Groups version: $($groupsModule.Version.ToString())" + +# This is what we want to check in our test +if ($appsModule.Version.ToString() -eq $authModule.Version.ToString() -and + $groupsModule.Version.ToString() -eq $authModule.Version.ToString()) { + Write-Host "Test passed - all modules have the same version" + exit 0 +} else { + Write-Host "Test failed - module versions don't match" + exit 1 +} \ No newline at end of file diff --git a/tests/PSinLinuxCloudShellImage.Tests.ps1 b/tests/PSinLinuxCloudShellImage.Tests.ps1 index 1d0424b..6ce2bbe 100755 --- a/tests/PSinLinuxCloudShellImage.Tests.ps1 +++ b/tests/PSinLinuxCloudShellImage.Tests.ps1 @@ -203,6 +203,39 @@ Describe "PowerShell Modules" { } + It "Microsoft.Graph modules can be imported in any order" { + # This test verifies that Microsoft.Graph.Applications and Microsoft.Graph.Groups + # can be imported in any order without version conflicts + try { + Import-Module Microsoft.Graph.Applications -Force -ErrorAction Stop + Import-Module Microsoft.Graph.Groups -Force -ErrorAction Stop + + # Verify modules were loaded successfully + $appsModule = Get-Module Microsoft.Graph.Applications + $groupsModule = Get-Module Microsoft.Graph.Groups + $authModule = Get-Module Microsoft.Graph.Authentication + + $appsModule | Should -Not -BeNullOrEmpty + $groupsModule | Should -Not -BeNullOrEmpty + $authModule | Should -Not -BeNullOrEmpty + + # Verify all modules are using the same version of Microsoft.Graph.Authentication + $authVersion = $authModule.Version.ToString() + $appsVersion = $appsModule.Version.ToString() + $groupsVersion = $groupsModule.Version.ToString() + + Write-Host "Microsoft.Graph.Authentication version: $authVersion" + Write-Host "Microsoft.Graph.Applications version: $appsVersion" + Write-Host "Microsoft.Graph.Groups version: $groupsVersion" + + $appsVersion | Should -Be $authVersion -Because "All Microsoft.Graph modules should use the same version" + $groupsVersion | Should -Be $authVersion -Because "All Microsoft.Graph modules should use the same version" + } + catch { + $_.Exception.Message | Should -BeNullOrEmpty -Because "No exceptions should be thrown when importing Microsoft.Graph modules" + } + } + $importModuleTestCases = @( @{ ModuleName = "Microsoft.PowerShell.Management" } @{ ModuleName = "PSCloudShellUtility" } @@ -214,17 +247,30 @@ Describe "PowerShell Modules" { @{ ModuleName = "MicrosoftTeams" } @{ ModuleName = "Microsoft.PowerShell.SecretManagement" } @{ ModuleName = "Microsoft.PowerShell.SecretStore" } + @{ ModuleName = "Microsoft.Graph.Authentication" } + @{ ModuleName = "Microsoft.Graph.Applications" } + @{ ModuleName = "Microsoft.Graph.Groups" } ) It "Import-Module test for " -TestCases $importModuleTestCases { param($ModuleName) try { - Import-Module $ModuleName -Force -ErrorAction Stop -ErrorVariable ev - $ev | Should -BeNullOrEmpty + Import-Module $ModuleName -Force -ErrorAction Stop + $module = Get-Module $ModuleName + $module | Should -Not -BeNullOrEmpty + + # Verify Microsoft.Graph modules have the correct version + if ($ModuleName -like "Microsoft.Graph*") { + $authModule = Get-Module "Microsoft.Graph.Authentication" + if ($authModule) { + $authVersion = $authModule.Version.ToString() + $module.Version.ToString() | Should -Be $authVersion -Because "All Microsoft.Graph modules should use the same version" + } + } } catch { - "Unexpected exception thrown: $_" | Should -BeNullOrEmpty + $_.Exception.Message | Should -BeNullOrEmpty -Because "No exceptions should be thrown when importing $ModuleName" } }