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{
param(
[Parameter(Mandatory)]
[String]$ComputerName
)
Begin{
$ErrorActionPreference
Write-Verbose "In Begin Block: Get-Details"
$lrt = @()
$freespaceC=@()
}
Process{
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"
}
}
end{
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 ?
HI,
thanks for replying back.
no error. on powershell app it is giving output of three different types .
Thanks
AM
Mamidwar_Anil_Ramlu:
image1700×703 45.6 KB
@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
jeevith
(Jeevith Hegde, Ph.D.)
April 13, 2022, 7:08pm
6
Hi @Mamidwar_Anil_Ramlu ,
To make things easier from the output of PowerShell.
Convert the three different values (datetime, int, string) to strings
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
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.
"Param(
[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)
3 Likes
Hey Thanks, this worked like a charm .
thanks again for a brief explanation
jeevith
(Jeevith Hegde, Ph.D.)
April 18, 2022, 1:19pm
8
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.
system
(system)
Closed
April 21, 2022, 1:20pm
9
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.