Hello,
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).
- End of inner exception stack trace - - -
-
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 2.8.5.201 -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
$email="automation@mckenneys.com"
$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 https://ps.outlook.com/powershell -Credential $credBshaheen -Authentication Basic -AllowRedirection
Import-PSSession $SESSION
Import-Module (Import-PSSession $SESSION -AllowClobber) -Global
Connect-MsolService -Credential $credBegadAdmin