Please note that VisualCron support is not actively monitoring this community forum. Please use our contact page for contacting the VisualCron support directly.


Dave Morgan
2013-09-09T20:56:01Z
We just purchased VisualCron and were playing around with setting up the first couple of production tasks. Most of our current scheduled tasks have actions of running PowerShell scripts. As such, we were creating VisualCron jobs containing PowerShell tasks.

We've tried running scripts both from a UNC and from a drive local to the server where VisualCron is installed. We've also tried running PowerShell code directly in the task.

In all cases, the task always fails with an exit code of 77777 and the following output:

Exception in Task: Cannot invoke this function because the current host does not implement it.

Can you please help?
Sponsor
Forum information
KJDavie
2013-09-10T02:29:42Z
Hi Dave,

We do a fair bit of processing with Powershell from VisualCron.

Code Snippets (Using Powershell Script Text) are good as in circumstances where you want to use VisualCron Variables

- Basically Simple Commands or Processing

- Particular Directory Listings (example below)
- Interrogating file Headers and footers
- Complicated Regular Expression Processing . . . etc

Here is a Directory Listing example of Archive Sub Folders we use as input into a VC Loop

-- snip ---
# Directory Listing
# "D:\fileexchange_io"
# Recurse Subfolders
# Ending in *Archive
# Where its a folder ( IsContainer )
# ForEach Directory we want the full name
Get-ChildItem "{USERVAR(VisualCronDriveLocal)}{USERVAR(VisualCronFileexchange)}" -recurse -filter *Archive | Where-Object { $_.PSIsContainer } | foreach { $_.FullName }
-- snip ---

We do call *simple* scripts from here also if we need to.

--- *** ---

But basically for any decent PS scripts, we have found a better outcome is to invoke powershell as a command (Execute Task) and passing parameters is a better option as this is then a standalone, standard powershell execution that runs identically as if it is open in PowerShell ISE or PowerGUI.

I have attached an example print.

We do it this way to:
- Invoke the Powershell with a particular privilege (the Execution Privilege, not just the file access privilege)
- Have control over the default drive
- support certain commands we have issues with using the inline code method
e.g.

* Importing Modules (Powershell communities Extensions)

-- snip --
import-module pscx
-- snip --

* Using Our Internal Scripts (e.g. utilities here) we want to "Dot Include"

-- snip --
# Utilities
. "$HOME\Utilities.ps1"
-- snip --

I have attached the short wrapper we use and an example and 2 screen prints of us using it (one without parameters, one with)

The Second example (with Parameters) is a script we use to process High volume Folders and organise them into Year, YearMonth, or YearMonthDay Sub Folders which we do for most of our Archive Folders at the volumes we deal with.

We also use some Powershell code to retrieve VisualCron Variables from the appropriate server and use these in various powershell scripts.

This is done using the provided VisualCron API, and the Proof of Concept I originally did is included in your VisualCron Install Folder:

Program Files (x86)\VisualCron\API\samples\PowerShell

Note Powershell versions and API changes have occured since so give these ones a try (Attached in the Second Zip File - Powershell 3 - VisualCron 7.0.x - (API 7.0)

VCAPI_Test.ps1
- Line 33 - Replace 'ServerNameHere' with your servername (or use the IP address example)
- Lines 39 & 42 - Replace User Variables "SERVER01" and "SERVER02" with variables you have setup on that server

VisualCron_API.ps1
- Line 22 - Replace YourVCUser with a VisualCron User valid on that server
- Line 23 - Replace YourVCPassword with the password for that VisualCron User valid on that server

. . . . for the sake of simplicity of the example . . . . the Password is Plain Text

Hope this gets you started !!
File Attachment(s):
RunPowershell.zip (1kb) downloaded 121 time(s).
VCAPI Example.zip (2kb) downloaded 97 time(s).
KJDavie attached the following image(s):
Dave Morgan
2013-09-10T04:46:32Z
Thanks for the detailed response KJ. That's very helpful! 😄 I don't know why I didn't think of doing it that way, as that's how we are currently doing it with Task Scheduler. And we also make extensive use of modules (PSCX as well as others). Tomorrow I'll try what you suggested and I suspect it will work very well. Thanks again!
Scroll to Top