.bat file to run multiple PowerShell commands and pass parameters

I am trying to run .bat file using “Start Process” activity and pass parameters - $un, $pwd but getting error during execution.

PowerShell script :

param(
[Parameter(Mandatory=$true)] $un,
[Parameter(Mandatory=$true)] $pwd
)

#Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser

$cred = New-Object System.Management.Automation.PsCredential($un, (ConvertTo-SecureString $pwd -AsPlainText -Force))

Import-Module MSOnline

Connect-MsolService -Credential $cred

Get-MsolAccountSku

Hi @Sonalk,
Here you have a nice tutorial for the Powershell scripting:

1 Like

@Pablito : Bot is trying to run commands in PowerShell(x86) which is causing errors - could not load module or assembly file.

Is it possible for bot to run commands in PowerShell (64 bit) instead of PowerShell (x86)?

1 Like

I don’t think this is related to your issue. Could you send an example of your project and eventually the full error stack you get?

@Pablito : Please find the attachment. It contains workflow, error details and PowerShell script.

It seems this module can’t be installed in PowerShell (x86). I am intrested whether it is possible to connect to Microsoft 365 using PowerShell (x86) or do i have to trigger PowerShell (64 bit) from PowerShell (x86) during the execution of this build.MSOnline.zip (69.6 KB)

Thank you. Indeed it looks like something that maybe we could improve (honestly I’m not super sure about it). I pushed this case to our dev team to check.

Btw. Please also check this site → Connect to Microsoft 365 with PowerShell - Microsoft 365 Enterprise | Microsoft Docs

They said that there are also some dependencies needed on the computer to run this Office365 Module. Maybe this is somehow related?

@Pablito : Have you found any issue in shared workflow?

Modules are actually available in their respective paths. Issue is coming during import modules.

I opened an internal ticket and the case is still under investigation process.

@ptrobot @Lakshmi_Holla : Any inputs or thoughts to perform alternative solution.

This script solves this issue for Bot to run commands in 32 bit using Invoke PowerShell activity.

Set-ExecutionPolicy Unrestricted -Scope CurrentUser
$PathToPowerShell64bit = Get-ChildItem -Path $Env:Windir\WinSxS | Where-Object {$_.FullName -match ‘amd64_microsoft-windows-powershell-exe’}
$PowerShell64bitExe = Get-ChildItem -Path $PathToPowerShell64bit.FullName -Filter PowerShell.exe | Select-Object -ExpandProperty FullName
& $PowerShell64bitExe -file ‘Path\MSOnline.ps1’

MSOnline.ps1 contains below commands :

$cred = Get-Credential
Import-Module MSOnline
Connect-MsolService -Credential $cred
Get-MsolAccountSku
Get-Process | Out-File -FilePath .\Process.txt
Start-sleep 10

Now i am building and testing script to pass credentials (instead of passing manually) and file path of MSOnline.ps1 as input parameters to script.

Is there way to use only one string as script? I don’t want to complicate and call another PowerShell script from specified path.

Objective is to use invoke PowerShell activity with two arguments only - Botusername and Botpassword.