Using Vcron variables/params in Powershell script? - VisualCron - Forum

Community forum

Carl-Johan
2013-11-14T13:22:30Z
Hi,
I am very new to Vcron. How do you use/access Vcron variables/params inside a Powershell script file? What do you need to do to get this to work? Anyone have some samples to share?

Cheers,
CJ
Support
2013-11-14T13:30:28Z
We will soon add support for incoming parameters. Meanwhile you can simply paste VisualCron Variables inside the script.
Henrik
Support
http://www.visualcron.com 
Please like  VisualCron on facebook!
Carl-Johan
2013-11-14T13:51:17Z
So inside my ps.1 file I should be able to add something like,


$siteUrl = "{LOOP(CurrentValueXArray,2)}"
$isSiteCollection = "{LOOP(CurrentValueXArray,5)}"

Don't get it to work? The .ps1 file is a step in a loop...

Any samples? Do I need to include any special snap-ins etc in my .ps1 file?

//CJ
Support
2013-11-14T14:08:22Z
I see, this only works if you specify code in the text field, not specifying a file. We will update this for next build. This build will probably be added to the Beta forum this week. Thanks for the report.
Henrik
Support
http://www.visualcron.com 
Please like  VisualCron on facebook!
Carl-Johan
2013-11-15T10:40:07Z
Henrik,
What if I want to assign a VCRON variable from Powershell? It works passing data in but how about "out" like,

"{USERVAR(errorcount)}" = $pSvariable

How do I do it?

//CJ
Support
2013-11-15T11:03:16Z
Originally Posted by: Carl-Johan 

Henrik,
What if I want to assign a VCRON variable from Powershell? It works passing data in but how about "out" like,

"{USERVAR(errorcount)}" = $pSvariable

How do I do it?

//CJ



You cannot assingn any other value but the output Variable like this:

write-output "Hello world!"

The output will then be visible as output in the output column and you can access it in next Task through:

{TASK(PrevTask,StdOut)}

You can also write to the error output:

write-error "My powershell script failed.. :("

And retrieve it through:

{TASK(PrevTask,StdErr)}
Henrik
Support
http://www.visualcron.com 
Please like  VisualCron on facebook!
Carl-Johan
2013-11-15T11:29:09Z
What about data conversions? If the value I get from {TASK(PrevTask,StdOut)}needs to be passed in to a SQL stored procedure as an Int? Is there a way to fix this?

//CJ
Support
2013-11-15T11:40:38Z
Yes, you define the parameter values and their types in the SQL Task. If you choose Int it will be converted when executed.
Henrik
Support
http://www.visualcron.com 
Please like  VisualCron on facebook!
Carl-Johan
2013-11-15T12:57:44Z
Hmm, not working. I have a user variable (of type string) that I assing the value from the StdOut (as described above). This value is a number such as '5'.
In the final step/task I am calling a stored procedure and passed in the value as in Int. How ever, when saving the final step VCCRON complains aboout the data type (I guess that means that we need to "un check" the validation rule, correct?)

Still don't work. Last step fails with a data conversion error.
Support
2013-11-15T13:41:57Z
I am not sure where it goes wrong for you. You need to turn validate off.

I tested by creating a stored procedure that takes two arguments;

* a string
* an integer

In the integer field I used a User Variable with value type string. It does not matter really as long as you have set the correct data type on the parameter in the SQL Task.
Henrik
Support
http://www.visualcron.com 
Please like  VisualCron on facebook!
osirisja
2013-11-15T14:39:25Z
Hi Carl-Johan

I am by no means a Powershell expert, but I have the following script defined in the internal Powershell task rather than an external .ps1 file. It probably isn't the best format or most efficient but it shows how VC variables can be transposed into the script in real time. Perhaps it will help someone?

#==========================================================
$env:ISIS_OMS_DOMAIN="-"
$env:ISIS_OMS_PORT="9091"
$env:ISIS_KEY_MODE="nooms"
$env:ISIS_COMMON="C:\isiscommv7"
$env:PATH=$env:ISIS_COMMON +"\w3\lib"+ ";"+$env:PATH
$prof = "{USERVAR(@TDPrf)}"
$deenv="{USERVAR(@TEnv)}"
$docdef = "{USERVAR(@TDocDef)}"
$inpfil = "{USERVAR(@TInfile)}"
$outfil = "{USERVAR(@TClientRoot)}\vctestdflt.AFP"
$logfile = "{USERVAR(@TActLog)}"
$exe = "c:\isis_v72\pdew3700\pdew3.exe"

$prjstr = "/compile /profile=$prof /docdef=$docdef /input=$inpfil $deenv"

$a = "$exe $prjstr"

Invoke-Expression $a | Out-File $logfile

write-output "COMPLETED"
#=======================================

I think for me the most useful is that Environment Variables can be set for the actual command - I'm not sure how otherwise this would be done in VC?

Cheers

Andy
KJDavie
2013-11-21T02:45:35Z
Hi Carl-Johan,

Not sure if you got an answer, but here is an earlier post where I showed passing parameters to powershell, and using the visualcron API to retrieve variable values from Powershell. That may help.

http://www.visualcron.com/forum.aspx?g=posts&m=16104#post16104 
Scroll to Top