Import-Module : Function Remove-MgSiteTermStoreSetParentGroupSetTermRelation cannot be created because function capacity 4096 has been exceeded for this scope
Explained everything in the Video : https://youtu.be/7-btaMI6wJI
Today I got below error when I tried to import my Graphs module to Powershell (Import-Module Microsoft.Graph)
Import-Module : Function Remove-MgSiteTermStoreSetParentGroupSetTermRelation cannot be created because function capacity 4096 has been exceeded for this scope.
At line:1 char:1
+ Import-Module Microsoft.Graph
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (Remove-MgSiteTe...SetTermRelation:String) [Import-Module], SessionSta
teOverflowException
+ FullyQualifiedErrorId : FunctionOverflow,Microsoft.PowerShell.Commands.ImportModuleCommand
After lot of research I identified that this is a known issue that occurs when importing Microsoft.Graph module in PowerShell 5.1, because the module has more than 4096 functions and PowerShell 5.1 has a limit on the number of functions that can be created in a scope.
There are some possible workarounds that you can try to resolve this error:
- Upgrade to PowerShell 7+ or latest as the runtime version (highly recommended). PowerShell 7+ does not have the function capacity limit and can import the module without any errors.
- Set $maximumfunctioncount variable to its max value, 32768, before importing the module. This will increase the function capacity limit for your scope, but it may not be enough if you have other modules loaded or if the Microsoft.Graph module adds more functions in the future.
To check all Maximum value set in PowerShell
gv Max*Count
To set the Maximum Function Count
$MaximumFunctionCount = 8096
I hope this helps you understand how to fix the error and import the Microsoft.Graph module successfully.