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 !!
Edited by user
2013-09-10T03:09:50Z
|
Reason: Add Powershell VCAPI Example
File Attachment(s):
KJDavie attached the following image(s):