0

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

aled
  • 21,330
  • 3
  • 27
  • 34
hpandalai
  • 438
  • 2
  • 13
  • 31
  • 1
    Try writing that code in several lines. Now, you have put quotes where they should not be. Besides, I'm guessing this was copied from the internet where the quotes were wrongly converted to HTML `"` entities.. – Theo Oct 26 '22 at 11:35
  • Thanks. The command is send thru an xml tag as the call is made from an Integration tools Mulesoft. I have edited the question and added the tag. – hpandalai Oct 26 '22 at 12:09
  • MuleSoft is a company. One of their products is Mule runtime, which is the one you are referring to as "integration tools". Please use correct terminology to avoid confusions. The code is in your Mule application, which is deployed into Mule runtime to be executed. – aled Oct 26 '22 at 14:16

2 Answers2

0

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

hpandalai
  • 438
  • 2
  • 13
  • 31
-1

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