Invoke powershell with powershell function not working

Hi , i have created a powershell function that takes 1 input parameter and return 3 output (string)parameters .
it is working good when executing in powershell but not in uipath (no output)

the powershell script is
#cmdlet for getting pre-patching info

#cmdlet for getting pre-patching info

Function Get-Prestats{

			Write-Verbose "In Begin Block: Get-Details"
			$lrt = @()
	        	if (Test-Connection -ComputerName $ComputerName -Quiet)
                  try {
				       $lrt= Get-Ciminstance -classname win32_operatingsystem -ComputerName $ComputerName|select-object -ExpandProperty lastbootuptime
					   $freespaceC=get-wmiobject win32_logicaldisk -computername $ComputerName | Where-Object{$_.DeviceID -eq "C:"} | Select-Object -ExpandProperty FreeSpace
				       $errno = 0
					 catch {
						 Write-Host "`nError Message: " $_.Exception.
						 $errno = 1
						 $errmesg =$_.Exception
               else {
			  Write-Host "Failed to ping the server : " $ComputerName
			  $errno = 1
			  $errmesg = "Failed to ping the server"
			return $lrt,$freespaceC,$ComputerName



1 Like

Hi @Mamidwar_Anil_Ramlu ,
Do you get an Error when executing the Activity ?

If so, Could you Provide us the Screenshot of it ?

If No Error, Does it mean the Output Values is Empty or is it returning a Different type of value ?


thanks for replying back.

no error. on powershell app it is giving output of three different types .



@Mamidwar_Anil_Ramlu , You are returning 3 different type values, Could you try by just passing a Single Return Value ?

Use a Message Box to Print the Output variable value and Post a Screenshot here

i changed my PS code for single output as you said , it is working for single return type but not for multiple output parameters

Hi @Mamidwar_Anil_Ramlu,

To make things easier from the output of PowerShell.

  1. Convert the three different values (datetime, int, string) to strings
  2. Output an array from your PowerShell script

Create an empty temporary array variable

$OutputArray = @()

Then populate your three values wherever you like using

$OutputArray += $lrt.ToString
$OutputArray += $freespaceC.ToString
$OutputArray += $ComputerName.ToString

Finally return $OutputArray

  1. Read the string array in UiPath (Output property contains the collection)

A sample PowerShell code. Here I just add some random strings (int, date and string) to the array after converting them.


      [Parameter(Mandatory=$true)] [String]$ComputerName             

$OutputArray = @()
$Space = 30

$OutputArray += Get-Date -format 'dd/MM/yyyy'
$OutputArray += $Space.ToString() 
$OutputArray += $ComputerName

return $OutputArray"

Sample file :
GetPowerShellOutputArray.xaml (6.4 KB)


Hey Thanks, this worked like a charm .

thanks again for a brief explanation

Hi @Mamidwar_Anil_Ramlu,

Kindly close this thread by marking the post which resolved your query. This way the solution is searchable by others using the advanced search function in the forum.

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