How to run a powershell script and fetch output?

Hi,

I am trying to invoke a powershell script(.ps1) and capture its output for finding the disk utilization of my computer.

Please suggest a solution.

Thanks in advance.

Hi Ashok,

Install package UiPath.Script.Activities (if you haven’t already) and use RunPowerShellScript activity.
Arguments should be straightforward, but please ask if something will not be working as expected.

Regards.

5 Likes

Thanks Andrej!! I will try and get back.

I have installed the package. And included the file path in “Filepath” textbox. When i try to run it throws me error. It says : AggregateException and System.Management.Automation.CmdletinvocationException.

Please suggest what could this possibly about because my standalone script works perfectly.

Hello,

yeah, this is a “command let” script exception.

remember that you got to have admin privileges to run power-shell scripts. does that happen when you run any other .ps1 file?

can you please upload your ps1 file and the xaml you are using for this automation? I can see no problem running scripts on CE.

regards

1 Like

Hi Andrzej,
Problem: Tried to compile UiPath.Script.Activities in VS and install. Epic fail.
Solved. Download packages from myget workflow activities

  1. Download UiPath.Script.Activities.1.0.6068.29800.nupkg. Add to local folder accessible to UiPath
  2. Try to install UiPath.Script.Activities (fails because of system.management.automation dependency)
  3. download system.management.automation.6.1.7601.17515.nupkg to same folder.
  4. restart UiPath. Install UiPath.Script.Activities

Edit 15 Nov 2017: UiPath.Script.Activities is not available at the myget workflow activities link above, nor at nuget.org apparently. As some forum members are reporting PowerShell script problems recently, I am uploading two packages that I have saved on my machine out of harm’s way, in case replacing the installed package helps.

UiPath.Script.Activities.1.0.6473.22268.nupkg (560.1 KB)
UiPath.Script.Activities.1.0.6068.29800.nupkg (560.0 KB)

Thanks a million,
burque505

1 Like

Interesting. For me it installs without issues and resolves the dependency by itself (but I’ve added nuget.org api in the sources previously).
Actually I don’t know why it’s not included by default.

2 Likes

I don’t see those activities on nuget.org, only UiPath, UiPath.ZipActivities, chromium_base and chromium_net.
NuGet page for UiPath

I’m having another problem with AutoHotkey.Interop.dll, though: dllexp.exe doesn’t show any exported functions for this. AutoHotkey.dll, on the other hand, has the functions in the file below.
AutoHotkeyDLLfunctions.zip (2.2 KB)
I also haven’t been able to pass any parameters to the scripts so far. I may try adding AutoHotkey.dll to a custom activity and see if that gets me any closer.
All I seem to be able to do with the script activity is run an AutoHotkey script. I’ve asked elsewhere on the forum, but it seems AutoHotkey is pretty much off the radar.
Regards,
burque505

Hi Andrzej ,

I am trying to do the same. But i am not able to install the required package. Can you please guide me through to complete this.

Thanks in Advance
Sushree Suravi

Hi All,

Since downloaded and installed the latest UiPath Studio (2017.1.6522 SP1), the PowerShell Script activity execution does not possibles.
We have the same error Message (cannot be loaded because running scripts is disabled on this system)

After desactivated All Security process (Set-ExecutionPolicy UNDEFINED -Scope LocalMachine) and running UiPath in Administrator right, I found the same error Message.

do you have an idea ?

@djunqua, can you share which version of UiPath.Script.Activities you have installed?

I am still using 1.0.6068.29800, although I see I can update to 1.0.6473.22268. I have also tried 1.0.6481.30155, but am not currently using it.

I have two of these available if you are not able to find them available to install easily, please see several posts above.

Using 1.0.6068.29800, the attached test workflow executes fine for me, same UiPath Studio version that you report.

Regards,
burque505

PowerShell.zip (1.3 KB)

1 Like

Hi @burque505 and thanks for your answer.
when I opening your main file, i have these messages on Main panel :
Activity could not be loaded because of errors in the XAML.

And on output panel, i have this error message :
Could not find type ‘RunPowerShellScript(Object)’ in namespace ‘http://schemas.uipath.com/workflow/activities’. Row: 55, Column: 4

you can find an exemple of UiPath program with “Invoke PowerShell” activity instead of “Run power shell script” (in your script)
PowerShell Activity.zip (1.6 KB)

@djunqua, I’m pretty sure that means a) you don’t have UiPath.Script.Activities installed, or b) it’s a different version. If you do have UiPath.Script.Activities installed, try a one-activity workflow of your own, with a single “Run Power shell script” pointing to the included .ps1 file.

Also, try executing the included .ps1 file outside of UiPath, i.e. from PowerShell. You should see the screenshot below.

Please let me know your results.

regards,
burque505This is a test

1 Like

Thanks for your answer.
I agree with your analyse, i don’t have UiPath.Script.Activities installed.
However, I don’t see this package from Manage Packages Listing (Filter Activites select or not)

When I used Windows PowerShell ISE, PowerShell, and UiPath for running your Script. This executed correctly, but only after set the ExecutionPolicy for the scope CurrentUser to bypass value.
Command used : Set-ExecutionPolicy bypass -scope CurrentUser

Here are the changes made to my script to be executed via UiPath :
$PShell = new-object -comobject wscript.shell
$PShell.(Set-ItemProperty -path $regKey ProxyEnable -value $proxyEnable);

Thanks for your help

1 Like

@djunqua, I don’t find it anywhere either, and it sometimes disappears when there is an update. Here are two versions you can try. I’m still using the earlier one. You may have to add it to the Packages directory in “C:\Users<you>\AppData\Local\UiPath\app-17.1.6522\Packages”, and even then it may not install. You might have to add a local package directory.

UiPath.Script.Activities.1.0.6473.22268.nupkg (560.1 KB)
UiPath.Script.Activities.1.0.6068.29800.nupkg (560.0 KB)

p.s. Another thing you --might-- do if it’s feasible on your system is to run UiPath as administrator (if it’s not already). That might avoid the ExecutionPolicy issue.

regards,
burque505

i am also facing same problem , unable to execute power shell , first tried to install “uipath.script.activities” from manage packages. i did not find. and later on downloaded the package and placed in “C:\Program Files\UiPath Studio\Packages” where i found other packages of the UI path are in. later when i went to manage packages , i do not
i don’t know whether its because of this pasting the package or something , but i found the option to install "uipath.script.activities. but sadly when i clicked the install button, one more exception came
some dependency missing this time ,
struck again kindly guide me ,
2017/12/04 15:25:00.935 Error System.InvalidOperationException: Unable to resolve dependency ‘System.Management.Automation (= 6.1.7601.17515)’.
at NuGet.InstallWalker.OnDependencyResolveError(PackageDependency dependency)
at NuGet.PackageWalker.Walk(IPackage package)
at NuGet.InstallWalker.ResolveOperations(IPackage package)
at NuGet.PackageManager.Execute(IPackage package, IPackageOperationResolver resolver)
at NuGet.PackageManager.InstallPackage(IPackage package, FrameworkName targetFramework, Boolean ignoreDependencies, Boolean allowPrereleaseVersions, Boolean ignoreWalkInfo)
at NuGet.PackageManager.InstallPackage(IPackage package, Boolean ignoreDependencies, Boolean allowPrereleaseVersions)
at UiPath.Project.PackageRepository.InstallPackage(PackageModel package, Boolean ignoreDependencies)
at UiPath.Project.PackageRepository.<>c__DisplayClass4.b__3()
"

how do you pass parameters and get output to and from your script using this activity? Thank you!!!

1 Like

Hi,
I,m also having the issue while running the power shell script through UiPath. The below exception poped-out ,

Throw : File C:\Users\Tharmarajan.s\Desktop\PS.ps1 cannot be loaded because running scripts is disabled on this system. For more information, see about_Execution_Policies at about Execution Policies - PowerShell | Microsoft Learn.

I think the script has to run as adminstrator permission, but how can I give that access in the Invoke Power shell activity ?

What is the “output” from invoking the script? Is it variable in the script, or what the script writes as output?

The output object looks like its IEnumerable String correct? No matter what I use – I never get any output. Maybe someone has an example xaml that shows this?

Thanks.

1 Like

Hi folks,

i’m too interested in get the output from invoke powershell to use in uipath activities.
please could anyone how reach this?.

thanks :wink: BR.