How to Integrate PowerShell into UiPath Workflows
PowerShell is a complex framework developed by Microsoft that allows for task automation and configuration management.
We want to provide our users with the option to integrate PowerShell and its powerful capabilities into the UiPath workflows. Integration is made through the InvokePowerShell activity. Usage may differ from one workflow to another - you can invoke simple commands/cmdlets or run complex scripts and jobs.
In the attached example (ReadTextFile workflow), the InvokePowerShell activity is used two times:
1. To return all the .txt files from the current directory (the workspace of the workflow).
2. To get the content from each of the .txt files found in the current directory.
1. Create a .txt file (Example.txt), containing the text "PoweShell is awesome!". The WriteTxtFile activity is used.
2. Get the .txt files from the current directory using
Get-ChildItem cmdlet with 2 parameters: Filter (to return only the .txt files) and Recurse. The parameters are set by adding them in the Parameters collection.
The result is a collection of FileInfo (it was changed using the TypeArgument property from Collection of PSObject to Collection of FileInfo).
3. Then we start a ForEach iteration, which will process each of the .txt files found at the previous step.
4. For each file, we will use InvokePowerShell activity with
Get-Content cmdlet that will read the content of the file and save it into the contents collection.
5. A message box with the first line of the file (index is 0 - contents(0).tostring) pops up.
We plan to develop more in the PowerShell area and we will try to improve both - the PowerShell activities pack and the specific documentation.
Note: The workflow is tested with UiPath Studio 8.