PSI: Using $Test in ExchangeOnline PowerShell Scripts

Posted by TheBlueFireKing@reddit | sysadmin | View on Reddit | 13 comments

In the last days we suddenly had multiple scripts fail with the following Error:

Cannot convert value "System.Management.Automation.PSCustomObject" to type "System.Boolean". Boolean parameters accept only Boolean values and numbers, such as $True, $False, 1 or O. (Cannot convert value "System.Management.Automation.PSCustomObject" to type "System.Boolean". Boolean parameters accept only Boolean values and numbers, such as $True, $False, 1 or O. (Cannot convert value
"System.Management.Automation.PSCustomObject" to type "System.Boolean". Boolean parameters accept only Boolean values and numbers, such as $True, $False, 1 or O.))

There were no changes to the Script itself. We are running them over AzureAutomate on Hybrid Workers. Up to date ExchangeOnline Module running Windows Powershell.

Now we do have the following parameter on most scripts so we can run / test them without it doing modifications:

param
(
  [Parameter(Mandatory = $False)]
  [Bool] $Test = $False
)

Now it seems like Microsoft push some kind of change that the Get-Mailbox cmdlet now internally sets the variable $Test to something else which triggers the error. Why the f $Test would be set in a Prod environment is beyond me.

We changed all $Test to another variable name and everything is running fine again.

Just dropping this here if someone else runs into this problem ...