msgraph-sdk-powershell icon indicating copy to clipboard operation
msgraph-sdk-powershell copied to clipboard

import-module with $MaximumFunctionCount = 32768 fails in PowerShell 5.1

Open Tarjei-stavanger opened this issue 3 months ago • 5 comments

Describe the bug

import-module microsoft.graph with $MaximumFunctionCount = 32768 fails in PowerShell 5.1 when the variable is set in the script, but works fine if it is done on the command line.

##
## Setting in script
##

if ( 32768 -gt $MaximumVariableCount ) {

    $MaximumVariableCount = 32768;

};

if ( 32768 -gt $MaximumFunctionCount ) {

    $MaximumFunctionCount = 32768;

};

"MaximumVariableCount $MaximumVariableCount ";
"MaximumFunctionCount $MaximumFunctionCount";

Image

Script display unfortunately with error messages in Norwegian. But you get the drift.

Image

BTW. I know this works fine in PowerShell 7.x, but those who run this might not have that installed.

Expected behavior

That import-module works the same whether it is a script or on command line in PowerShell 5.1.

How to reproduce

Run script or copy commands from script to command line.

SDK Version

No response

Latest version known to work for scenario above?

No response

Known Workarounds

No response

Debug output

Click to expand log ```
</details>


### Configuration

_No response_

### Other information

_No response_

Tarjei-stavanger avatar Sep 29 '25 08:09 Tarjei-stavanger

It looks like the images I attached disappeared.

Tarjei-stavanger avatar Sep 29 '25 08:09 Tarjei-stavanger

Can you please share the script where you are attempting to set the variables and import the module within the scope of the script?

gavinbarron avatar Oct 20 '25 21:10 gavinbarron

As shown in the screenshots, the variable has the required value since it is set before it is displayed.

##
##
## Add groups for Conditional Access
##
##
##
## Must have Administrator access
##
##

if ( 32768 -gt $MaximumVariableCount ) {

    $MaximumVariableCount = 32768;

};

if ( 32768 -gt $MaximumFunctionCount ) {

    $MaximumFunctionCount = 32768;

};

"   MaximumVariableCount $MaximumVariableCount";
"   MaximumFunctionCount $MaximumFunctionCount";

$error = '';


"    Import of  Microsoft.Graph takes time";

Import-Module microsoft.graph;

"    Microsoft.Graph importeed";

"    Connect-MpGraph starts";

Connect-MgGraph -NoWelcome -Scopes 'Policy.ReadWrite.ConditionalAccess', 'Group.Read.All';

"    Connect-MpGraph finished : $error<";

Tarjei-stavanger avatar Oct 21 '25 05:10 Tarjei-stavanger

Sorry, I missed that was the script contents.

gavinbarron avatar Oct 21 '25 15:10 gavinbarron

Thanks for having a look.

Tarjei-stavanger avatar Oct 25 '25 17:10 Tarjei-stavanger