I was running some Powershell commands on an alternative server today and I got the error shown below, this error does not occur in Powershell 7 (which is where all my script development usually occurs from) but only normal and good original Powershell:
Function Test-ArchiveConnectivity cannot be created because function capacity 4096 has been exceeded for this scope.
At C:\Program Files\WindowsPowerShell\Modules\ExchangeOnlineManagement\3.1.0\netFramework\ExchangeOnlineManagement.psm1:733 char:21
+ throw $_.Exception;
+ ~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (Test-ArchiveConnectivity:String) [],
ParentContainsErrorRecordException
+ FullyQualifiedErrorId : FunctionOverflow
It seems to select a ransom variable and fail on that variable, weird, been using Powershell for years now and this is the first time this has occurred, however apparently I have loaded more than 4096 variables and Powershell is not happy.
Note : This occurred for me after installed the preview module for Microsoft Graph, after removing this I no longer need the variable limited increased.
Let us check the variables allowed with this command, and I expect this to be 4096:
Get-Variable Max*Count
That confirms that that is indeed the maximum variable count limit, you can see the bottom value:
So we need to set this higher that 4096 as we have that many variables already set, so from Powershell run this:
$MaximumFunctionCount = 8192
$MaximumVariableCount = 8192
After running this command you can see that yes, indeed the variable count has been increased:
I usually use Powershell 7, however when running code of other servers it is not always installed, however I would recommend you to use Powershell 7 this is the release I am using here