Skip to content

Commit

Permalink
show error when mg module v2 is loaded
Browse files Browse the repository at this point in the history
  • Loading branch information
jazuntee committed Jan 28, 2023
1 parent dd132bb commit 69a719c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/MSIdentityTools.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@

# Modules that must be imported into the global environment prior to importing this module
RequiredModules = @(
@{ ModuleName = 'Microsoft.Graph.Authentication'; Guid = '883916f2-9184-46ee-b1f8-b6a2fb784cee'; ModuleVersion = '1.9.2'; MaximumVersion = '1.999.0' }
@{ ModuleName = 'Microsoft.Graph.Authentication'; Guid = '883916f2-9184-46ee-b1f8-b6a2fb784cee'; ModuleVersion = '1.9.2' }
)

# Assemblies that must be loaded prior to importing this module
Expand Down
17 changes: 13 additions & 4 deletions src/internal/Test-MgCommandPrerequisites.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,27 @@ function Test-MgCommandPrerequisites {
)

begin {
[array] $MgAuthenticationModule = Get-Module 'Microsoft.Graph.Authentication'
if (!$MgAuthenticationModule) {
$MgAuthenticationModule = Import-Module 'Microsoft.Graph.Authentication' -PassThru -Verbose:$false
[version] $MgAuthenticationModuleVersion = $null
$Assembly = [System.AppDomain]::CurrentDomain.GetAssemblies() | Where-Object FullName -Like "Microsoft.Graph.Authentication,*"
if ($Assembly.FullName -match "Version=(([0-9]+.[0-9]+.[0-9]+).[0-9]+),") {
$MgAuthenticationModuleVersion = $Matches[2]
}
else {
$MgAuthenticationModuleVersion = Get-Command 'Connect-MgGraph' -Module 'Microsoft.Graph.Authentication' | Select-Object -ExpandProperty Version
}
[version] $MgAuthenticationModuleVersion = $MgAuthenticationModule[0].Version
Write-Debug "Microsoft.Graph.Authentication module version loaded: $MgAuthenticationModuleVersion"
}

process {
## Initialize
$result = $true

## Temporary Error when Mg Module v2 is loaded. Remove once all commands have been updated and increase module dependancy minimum to v2.
if ($MgAuthenticationModuleVersion -ge [version]'2.0.0' -and $ApiVersion -eq 'beta') {
Write-Error -Category ResourceUnavailable -ErrorId 'MgModuleNotSupported' -Message ("This command is not yet compatible with Microsoft Graph SDK Module v2 and the currently loaded 'Microsoft.Graph.Authentication' module is version '{0}'. To resolve, try opening a new PowerShell session, importing an older version of the module, and running the command again." -f $MgAuthenticationModuleVersion) -RecommendedAction ("Import-Module Microsoft.Graph.Authentication -MinimumVersion '{0}' -MaximumVersion '1.99.0'" -f $MinimumVersion)
return $false
}

## Get Graph Command Details
[hashtable] $MgCommandLookup = @{}
foreach ($CommandName in $Name) {
Expand Down

0 comments on commit 69a719c

Please sign in to comment.