Executing powershell

Hi,

I want to execute below powershell using “Invoke powershell activity”. This script is running fine while running outside of uipath however while executing same through uipath, I am getting “Command not Found” exception. Please help.

$Outlook = New-Object -ComObject Outlook.Application

$Mail = $Outlook.CreateItem(0)

$Mail.To = "kapil.parmar@cognizant.com"

$Mail.Recipients.Add("kapil.parmar@cognizant.com")

$Mail.Subject = "New Request"

$html = @"

<p>Kindly approve/reject the request</p>

<table cellspacing="0" cellpadding="0">

<tr>

<td align="center" width="100" height="40" bgcolor="#ffffff" style="-webkit-border-radius: 5px; -moz-border-radius: 5px; border-radius: 5px; color: #ffffff; display: contents;">

<a href = mailto:kapil.parmar@cognizant.com&subject="Approved"&body="Approved" style="font-size:16px; font-weight: bold; font-family: Helvetica, Arial, sans-serif; text-decoration: none; line-height:40px; width:100%; display:contents"><span style="color: #674b08">Approved</a>

</td>

</tr>

</td>

</tr>

</table>

<br/>

<table cellspacing="0" cellpadding="0">

<tr>

<td align="center" width="100" height="40" bgcolor="#000091" style="-webkit-border-radius: 5px; -moz-border-radius: 5px; border-radius: 5px; color: #ffffff; display: block;">

<a href = mailto:kapil.parmar@cognizant.com&subject="Rejected"&body="Rejected" style="font-size:16px; font-weight: bold; font-family: Helvetica, Arial, sans-serif; text-decoration: none; line-height:40px; width:100%; display:inline-block"><span style="color: #FFFFFF">Rejected</a>

</tr>

</table>

"@

$Mail.HTMLBody = $html

$Mail.Send()

I’ve tried to run your code and it’s working for me. I’m using “Run power shell script” activity.

There is only ‘Invoke Power Shell’ activity in UiPath. Could not find ‘Run Power Shell’ activity.

Package name uipath.scripts something

try to create the body outside the script and pass it as a variable

Did same but facing same issue. I have copied entire exception from catch block and have pasted below.

Transaction error execution started
System.Management.Automation.CommandNotFoundException: The term '$Outlook = New-Object -ComObject Outlook.Application
$Mail = $Outlook.CreateItem(0)

$Mail.To = “kapil.parmar@cognizant.com
$Mail.Recipients.Add(“kapil.parmar@cognizant.com”)
$Mail.Subject = “New Request”

$html = @"

Kindly approve/reject the request

<a href = mailto:kapil.parmar@cognizant.com&subject="Approved"&body="Approved" style="font-size:16px; font-weight: bold; font-family: Helvetica, Arial, sans-serif; text-decoration: none; line-height:40px; width:100%; display:contents"><span style="color: #674b08">Approved</a>
</td> 
</tr>     
</td> 
</tr> 

Rejected

"@

$Mail.HTMLBody = $html
$Mail.Send()’ 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.
at System.Activities.Statements.Throw.Execute(CodeActivityContext context)
at System.Activities.CodeActivity.InternalExecute(ActivityInstance instance, ActivityExecutor executor, BookmarkManager bookmarkManager)
at System.Activities.ActivityInstance.Execute(ActivityExecutor executor, BookmarkManager bookmarkManager)
at System.Activities.Runtime.ActivityExecutor.ExecuteActivityWorkItem.ExecuteBody(ActivityExecutor executor, BookmarkManager bookmarkManager, Location resultLocation)
Transaction error execution ended in: 00:00:01