Powershell Pass Variables or Arrays to VisualCron - VisualCron - Forum

Community forum

Kevin J Linna
2017-08-26T16:20:49Z
VisualCron Job contains a PowerShell Task.

The PowerShell Task runs and I can write out a script variable so that it is passed to "output" or STDOUT which VisualCron can pull in and use.

My question is if I can pass multiple additional variables from PowerShell script out to a usable variable in VisualCron.

If I write a 1 or 0 INT to STDOUT I can use it for decision making in subsequent tasks, or I can use it as a variable in a notification etc....

But if my PowerShell creates 20 variables that I need to pass back to VisualCron I can't find a way to do that.
Please Advise if this is possible to pass all my variables or arrays from a PowerShell task back into VisualCron for use.

Thanks,
Support
2017-08-28T19:04:15Z
You can return, maybe a, pipe or semicolon separated answer and then split it in VisualCron. There are methods to parse this out like Variable;

{STRING(GetColumn|2|2|,|1,A
2,B
3,C)}

or

{STRING(GetColumn|2|\r\n|2|,|1,A\r\n2,B\r\n3,C)}
Henrik
Support
http://www.visualcron.com 
Please like  VisualCron on facebook!
Kevin J Linna
2017-08-28T19:27:38Z
ok, adding everything in the STDOUT and parsing on the VisualCron side is where I have focused the last couple days.

So I am using: {STRING(FirstLine|{TASK(072b4318-a6c1-4c00-890d-53cd8b14eba2,StdOut)})}
to get the "pass/fail" variable

But all my other information follows on a Row basis....or Line basis.

I think there is only firstline and lastline to key on with string filtering correct?
or can you do Line 4-->Lastline
or Line 6 to line 22 (for example)

Here is an example of my output:
34
True
Arrowhead
255
Count Name
----- ----
9 HOST250
3 HOST500
7 HostServer1
4 HostServer2
2 HostLaptop3
22 HostLaptop4
4 HostPC5
2367 HostPC6

I guess I could split them up into multiple PS scripts and then use each STDOUT separately as it's own variable as well, just a bit cumbersome.
SnapDiligence
2017-08-28T20:00:31Z
Originally Posted by: Kevin J Linna 

ok, adding everything in the STDOUT and parsing on the VisualCron side is where I have focused the last couple days.

So I am using: {STRING(FirstLine|{TASK(072b4318-a6c1-4c00-890d-53cd8b14eba2,StdOut)})}
to get the "pass/fail" variable

But all my other information follows on a Row basis....or Line basis.

I think there is only firstline and lastline to key on with string filtering correct?
or can you do Line 4-->Lastline
or Line 6 to line 22 (for example)

Here is an example of my output:
34
True
Arrowhead
255
Count Name
----- ----
9 HOST250
3 HOST500
7 HostServer1
4 HostServer2
2 HostLaptop3
22 HostLaptop4
4 HostPC5
2367 HostPC6

I guess I could split them up into multiple PS scripts and then use each STDOUT separately as it's own variable as well, just a bit cumbersome.


In the Powershell task, format your table to return parse-able strings. Here is a script I wrote to do that using a JSON string input (if you aren't using JSON, you probably should modify that part of the script):

Quote:


param(
[Parameter(Mandatory = $true)]
[string]$JsonFileIn
)

$jsonObj = (Get-Content $JsonFileIn) -join "`n" | ConvertFrom-Json

$columnNames = New-Object System.Collections.Generic.List[String]

$jobConfigurationsArray = $jsonObj.PSObject.Properties.Value

ForEach($jobConfigurationObject in $jobConfigurationsArray)
{
ForEach($property in $jobConfigurationObject.PsObject.Properties)
{
if ($property.Name -notin $columnNames)
{
$columnNames.Add($property.Name)
}
}
}

[string]$formatTableConfigString

$tableConfigurationsScriptArray = @()

ForEach($columnName in $columnNames)
{
$expressionString = "`"```"{0}```"```~`" -f `$_.$columnName"
$expression = [scriptblock]::Create($expressionString)
$hashtableNameScript = @{Name = "$columnName"; Expression = $expression}

$tableConfigurationsScriptArray += $hashtableNameScript
}

Write-Output $jobConfigurationsArray | Format-Table $tableConfigurationsScriptArray |Out-String -Width 8000



This'll return tilde separated, dbl quote qualified output that directly mirrors your table. Of course, that means it has the 2nd row with the dashes. Swap out the tilde in $expressionString = "`"```"{0}```"```~`" -f `$_.$columnName" with the delimiter of your choice. You can also remove the dbl quotes (with their three single quote escape characters) around the {0} to remove the dbl quote qualification. This script is/was a quick and dirty fix, so you might have to do some of your own work to get it working how you want.

If you do a "Set Job Variable Task" with the value {STRING(GetColumn|3|1|~|)} and another "Set Job Variable Task" with the value {STRING(GetColumn|3|2|~|)} you should get your "9" and "HOST250". If you slap a loop on top of it starting on row 3 (start on 2 as the loop array starts at zero), you can instead use {LOOP(CurrentValueXArray,0)} and {LOOP(CurrentValueXArray,1)} to get your values in each row out and set as job variables. At that point, you can put tasks within the loop that use those values. Of course, if you can't put it into a loop, you'd need to just set up 40ish "Set Job Variable Tasks" to extract all 2 values for each of the 20 variables.
Kevin J Linna
2017-08-28T20:12:00Z
Thanks everyone for the valuable input and information. I definitely have what I need to work around VisualCron handling variables created in Powershell tasks.
Much appreciated.
Scroll to Top