How to use Run Power Shell Activity

I am trying to run powershell script in uipath and i’m getting the error which states ‘One or more errors occurred’. Can anyone help here. Screenshot is attached with the script i’ve written, parameters defined and the workflow.
Thanks.

I have tried it another way

Hi @rameezimtiaz,
In you script I don’t see where are you using those parameters/variables (user, password etc.).

@Pablito i have 3 parameters in parameter property.
IF you can can you please write me a proper script?
Screenshot of parameters is shared below

I tried the following script as well

But where in Script are You using those parameters? You only declaring them, but those are not used in the script anywhere.

@Pablito I have updated the script and the following error occurred. Can you help?
Thanks

@Pablito i was able to change the script and fix that error only to get a new error

Let me explain this. If you are doing the script with variables (in you case $Name, $Password and $UserPricipalName) you have to use them in the script somewhere. Example:

$Credentials = Get-Credential
$ComputerName = "MyPC"

Enter-PSSession -Computername $ComputerName -Credential $Credentials

So once again. Where are you using Name, Password and UserPricipalName in your script? I see only declaration of them but without of using them anywhere.

@Pablito I have tried everything but i am unable to run this. I have changed the script now but still im getting error. I am sharing my script

Param(

[Parameter(Mandatory=$true)] [string]$Name,
[Parameter(Mandatory=$true)] [string]$Password,
[Parameter(Mandatory=$true)] [string]$UserPrincipalName

)

Add-PSSnapin Microsoft.Exchange.Management.PowerShell.SnapIn
$Password = ConvertTo-SecureString -String “ABC123##” -AsPlainText -Force
$Name = “Rameez”
$UserPrincipalName = "rameez@cantest.com"
New-Mailbox -UserPrincipalName $UserPrincipalName -Name $Name -Password $Password

@Pablito i’ll explain what im trying to do

I want to create an exchange account from uipath studio through powershell and the script i shared in my last post works absolutely fine when i directly run it on powershell but i get the following error when i run it in uipath studio.

The term ‘New-Mailbox’ is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

Is the Add-PSSnapin Microsoft.Exchange.Management.PowerShell.SnapIn command working by default in PowerShell (not Studio)? If yes, then try to include a little pause before you will do New-Mailbox command. Probably this command is trying to run immediately before snapin is loaded.

[quote=“Pablito, post:12, topic:149692”]
Add-PSSnapin Microsoft.Exchange.Management.PowerShell.SnapIn
[/quote] this command works in powershell but not in uipath for some odd reason. I tried running this command separately and the error i got was that command is not supported on windows powershell which is odd. but i was able to create exchange account writing another script.
@Pablito thanks for your help in pointing out mistakes in my script which helped in solving my problem

@Pablito do ou have any idea how this command works in uipath?
Enter-PSSession -ComputerName “canonextest.cantest.com

Whenever I run it i get an error stating “The method or operation is not implemented.”
What i’m trying to do now is that accessing my exchange machine from within another machine which is on same network.

Check this screenshot

First of all the second machine to which you are trying to connect need to have remote scripting enabled, otherwise you will be constantly blocked. It can be done by running specific commands in powershell on second machine. You can easily check this on internet.

Second thing. If remote scripting is enabled ‘Enter-PSSession’ is not that perfect approach as it’s switching your current PS console connection to second machine, so you are not able to do anything locally until you will not close the connection. Better approach is to use ‘Invoke-Command’.

@Pablito i tried this way

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.