Run PowerShell Script in StudioX without 'Invoke Power Shell'

Can this be done without ‘Invoke Power Shell?’ I’m using 2020.10.2

Hi @michael.massicotte,

what exactly are you trying to use instead of “invoke PowerShell”? It occurs to me you may compile a batch file and run it using the “Use Application” card

Powershell script line
Get-ChildItem -Path “[sync-mapped shared drive as Windows folder]” -Recurse | Select-Object fullname,directoryname, name, lastwritetime | Export-Csv -Path C:\Temp\MonthlyFileScan\PS_GetOutput_CSV.csv -Encoding ascii -NoTypeInformation

Haha, UIPath’s bot said I should mark this post as solved, even though I still have no answer on how to execute a Powershell script via StudioX.

Without knowing exactly how / why you want to run the script this way, I can suggest these two options as rough workarounds to using Invoke PowerShell:

  1. Run PowerShell.exe with the Start Process activity and pass script line through as an argument using the “-Command” parameter, or using the “-File” parameter with the file path if you saved the script in a .ps1 file. If you decide to use the “-Command” parameter I would suggest saving the full argument in a string variable as it simplifies passing it to the activity a bit. Pay careful attention to properly escaping nested quotes.

  2. Run PowerShell.exe with the Open Application activity and use the Type Into activity to type out your command, followed by pressing the enter key (for example, “ping google.com” + “[k(enter)]”). This method is slightly simpler to create but slower and more intrusive.

As a third (not really recommended) option you can use one the above methods, but calling PowerShell with the script commands / file via command prompt (e.g. PowerShell -File C:\TEMP\MyNotepadScript.ps1). Only use this if there is some reason why you cannot use PowerShell directly.

Ruan, Thanks much for your reply. I can’t attempt suggestions 1 or 2 in StudioX because neither the START PROCESS nor OPEN APPLICATION activities seem to be available in 20.10.2, which is the version currently fielded within my org. Suggestion 3 works perfectly, though, with a USE APPLICATION followed by a TYPE INTO activity aimed at the Windows Taskbar Search cell.

Following suggestion #3, the TYPE INTO activity…

TEXT property is… powershell -file “C:\Temp\MonthlyFileScan\GetSpMappedToLocalFileInventorytoCSV.ps1”<[“[k(enter)]”.ToString]>

or, viewing it through the ADVANCED EDITOR line is…
string.Format("powershell -file ““C:\Temp\MonthlyFileScan\GetSpMappedToLocalFileInventorytoCSV.ps1"”{0}”, “[k(enter)]”.ToString)

This activity types the full path of the PowerShell script file into the Search cell and electronically activates the ENTER key to execute the command line.

There may be equally good alternatives but this seems to be a good StudioX workaround for now. Appreciate the tips!

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