Home > Back-end >  Powershell Switch Parameter throws ParameterBindingException Exception
Powershell Switch Parameter throws ParameterBindingException Exception

Time:10-27

I have to execute the below script thru an Integration Tool Mulesoft. Unfortunately the switch parameter Confirm is throwing an error. The same script works from the powershell command line. Below is the command to execute:

Set-Location -Path 'C:\Windows\System32\WindowsPowerShell\v1.0\';powershell.exe -ExecutionPolicy RemoteSigned -noprofile -noninteractive  ". 'C:\Program Files\Microsoft\Exchange Server\V15\bin\RemoteExchange.ps1'; Connect-ExchangeServer -auto; Disable-MailUser -Identity abc.com/PEOPLE/xyzpqr -Confirm:$false"

Operation in flow:

<powershell:execute-command-exception-handling-enabled doc:name="Execute command (exception handling enabled)" doc:id="79bd2451-9441-49e7-8517-3bbd6a151fae" config-ref="Powershell_Configuration" command="Set-Location -Path 'C:\Windows\System32\WindowsPowerShell\v1.0\';powershell.exe -ExecutionPolicy RemoteSigned -noprofile -noninteractive  &quot;. 'C:\Program Files\Microsoft\Exchange Server\V15\bin\RemoteExchange.ps1'; Connect-ExchangeServer -auto; Disable-MailUser -Identity abc.com/PEOPLE/xyzpqr -Confirm:$false&quot;"/>

The error is as below

Message               : A positional parameter cannot be found that accepts argument '-Confirm:False'.
      CategoryInfo          : InvalidArgument: (:) [Disable-MailUser], ParameterBindingException
      FullyQualifiedErrorId : PositionalParameterNotFound,Disable-MailUser

Our PS version is 5.1 Any help would be greatly appreciated I tried

CodePudding user response:

After trying a lot of suggestions in Stackoverflow([How to convert string to boolean in this Powershell code for Exchange Online?][1]) etc here is what worked I did a cast -Confirm:([System.Convert]::ToBoolean(0)) and that worked. Strangely -Confirm:([System.Convert]::ToBoolean("False")) also didn't work. So a cast was required. Mulesoft Powershell connector must have been playing tricks. [1]: https://stackoverflow.com/questions/16983810/how-to-convert-string-to-boolean-in-this-powershell-code-for-exchange-online

CodePudding user response:

Assuming your local machine has a Windows OS , having the code working in your local makes sense. But It won't work in Cloudhub because it uses an EC2 instance under the hood with a Linux OS.

You can find more details about it in https://docs.mulesoft.com/runtime-manager/cloudhub-architecture#cloudhub-workers

  • Related