Issue with Run Powershell Script activity - Access Denied


I am trying to run a PowerShell script in UiPath using the package UiPath.Script.Activities. When running the PowerShell script, I get the following error in UiPath: RemoteException wrapping System.AggregateException: One or more errors occurred —> RemoteException wrapping System.Exception: Access is denied

      • End of inner exception stack trace - - -
        at UiPath.Script.Activities.PowerShell.RunPowershellSCript`1.EndExecute(AsyncCodeActivityContext context, IAsyncResult Result).

This is the current script:

Start-Process PowerShell -verb runas
Set-ExecutionPolicy Bypass -Scope CurrentUser
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Install-PackageProvider -Name Nuget -MinimumVersion -Force -Scope CurrentUser
Install-Module -Repository UiPath -Name UiPath.Powershell -Force -Scope CurrentUser
Import-Module UiPath.PowerShell
install-packageprovider -name Powershellget -force -Scope CurrentUser
Install-Module MSOnline -Scope CurrentUser
Install-Module AzureAD -Scope CurrentUser
install-module ExchangeOnlineManagement -Scope CurrentUser
$encryptedBegadAdmin = Get-Content ‘C:\Scripts\automationEncrypted.txt’|ConvertTo-SecureString
$encryptedBshaheen = Get-Content ‘C:\Scripts\automationEncrypted.txt’|ConvertTo-SecureString
$credBegadAdmin = New-Object System.Management.Automation.PSCredential($email,$encryptedBegadAdmin)
$credBshaheen = New-Object System.Management.Automation.PSCredential($email,$encryptedBshaheen)
$SESSION = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri -Credential $credBshaheen -Authentication Basic -AllowRedirection
Import-PSSession $SESSION
Import-Module (Import-PSSession $SESSION -AllowClobber) -Global
Connect-MsolService -Credential $credBegadAdmin

Hi @madison.mcmahon,

Refer this below article it might helps you:

Invoke-Powershell Activity throwing access level error


Thank you for the feedback @1996, After reviewing the article it looks like they are using the Invoke PowerShell activity. However, I am trying to use the Run PowerShell activity which is slightly different. I will try to update my packages and see if that helps.