Skip to content

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

@Tarjei-stavanger

Description

@Tarjei-stavanger

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";

Command line.
<img width="1114" height="419" alt="Image" src="https://github.com/user-attachments/assets/530abfae-1c55-4792-af25-b16b11367d86" />


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

<img width="1115" height="628" alt="Image" src="https://github.com/user-attachments/assets/7840709b-387e-4dba-b941-e05efa9d126a" />

 
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

<details><summary>Click to expand log</summary>
</details>


### Configuration

_No response_

### Other information

_No response_

Metadata

Metadata

Assignees

No one assigned

    Labels

    status:waiting-for-triageAn issue that is yet to be reviewed or assignedtype:bugA broken experience

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions