Friday, July 21 2006 on other
The other day I started looking into using PowerShell to help manage Captaris Workflow. The toughest part about coming up with any administration tool is imagining all the different tasks people might want to accomplish. One of the wonderful things about Powershell is that you don’t have to really know the details of how users want to manipulate the information. All you need to do is give the basic building blocks that can then be piped together to make something amazing. That was always the cool thing about piping commands in Unix. None of the individual utilities did much, but when piped together you could get amazing things done.
Anyway, one of the common tasks that Captaris Workflow admins like to do is to move old processes to an archive folder. We can do that via the GUI, but it is a multiple step process. So I created two simple Powershell scripts that will move any file, folder, process, or model from one location to another based on name, id, date modified, date created, owner, original location, and more. And to make it even better the two scripts together add up to 15 lines of code. If you only count the unique lines, its down to 9 lines.
So first off we want to get the list of records off the Workflow Server:
param($user=$(Throw "A user is required..."),$pwd="")
[void][System.Reflection.Assembly]::LoadWithPartialName("TeamplateBLL") |out-null
$s = New-Object Teamplate.BLL.BSession
$s.Connect($user,$pwd)$f = New-Object Teamplate.BLL.BFileList
$f.SetSession($s) | out-null[xml]$fld = $f.GetRecords()
return $fld.FileListDataSet.Files
This simply is connecting a session, using that session to get the list of records, then returning that list to the user. The next script just takes the ID of a record and moves it to the ID of another location:
param($FileID=$(Throw "A FileID is required..."),
$FolderID=$(Throw "A Destination FolderID is required..."),
$user=$(Throw "A user is required..."),
$pwd="")
[void][System.Reflection.Assembly]::LoadWithPartialName("TeamplateBLL") |out-null
$s = New-Object Teamplate.BLL.BSession
$s.Connect($user,$pwd)$f = New-Object Teamplate.BLL.BFileList
$f.SetSession($s) | out-null$f.MoveFile($FileID,$FolderID)
So now with these two scripts, which I have called get-wfrecords and move-wfrecord I can do some of the following really cool things:
To get just one of these done in 15 lines of code in Visual Studio is pretty easy. But to get the many different variations I have in the same number is pretty freaking cool. Basically now I have to come up with methods to output all the different types of things in the system, then think about the different ways admins want to manipulate them. Do any of my readers have any ideas? Anything you want to see?
> come up with methods to output all the different types of things
I am not sure what you meant exactly by that statement.
But a function can return a multiple values as following:
==============================
# MultiReturn returns more than one objects of different types
[^_^]PS[17]>function MultiReturn { "Hi", 1, @{one="foo";two="bar";three="baz"} }
[^_^]PS[18]>MultiReturn | % { $_.GetType().FullName }
System.String
System.Int32
System.Collections.Hashtable
# Do something with Each Object type
[^_^]PS[19]>MultiReturn | % {
>> switch ($_) {
>> { $_ -is [string] } { "Do something with String"; break; }
>> { $_ -is [int] } { "Do something with Integer"; break; }
>> { $_ -is [hashtable] } { "Do something with hashtable"; break; }
>> }
>> }
Do something with String
Do something with Integer
Do something with hashtable
==============================
Not only you can send the return values to the next pipeline,
you can also assign variables to each return values
==============================
# Assign each variable to the each return value
# $str will hold the first return value(of type String in this case)
# $int will hold integer value of "1"
# $hash will hold hashtable, @{one="foo";two="bar";three="baz"}
[^_^]PS[20]>$str, $int, $hash = MultiReturn
[^_^]PS[21]>$str
Hi
[^_^]PS[22]>$int
1
[^_^]PS[23]>$hash
Name Value
---- -----
two bar
three baz
one foo
==============================
DBMwS said on 7.21.2006 at 7:48 PM
I am not at all familiar with "Captaris Workflow"...
By the way,
> come up with methods to output all the different types of things
I am not sure what you meant exactly by that statement.
But a function can return multiple values as following:
==============================
# MultiReturn returns more than one objects of different types
[^_^]PS[17]>function MultiReturn { "Hi", 1, @{one="foo";two="bar";three="baz"} }
[^_^]PS[18]>MultiReturn | % { $_.GetType().FullName }
System.String
System.Int32
System.Collections.Hashtable
# Do something with Each Object type
[^_^]PS[19]>MultiReturn | % {
>> switch ($_) {
>> { $_ -is [string] } { "Do something with String"; break; }
>> { $_ -is [int] } { "Do something with Integer"; break; }
>> { $_ -is [hashtable] } { "Do something with hashtable"; break; }
>> }
>> }
Do something with String
Do something with Integer
Do something with hashtable
==============================
Not only you can send the return values to the next pipeline,
you can also assign variables to each return values
==============================
# Assign each variable to the each return value
# $str will hold the first return value(of type String in this case)
# $int will hold integer value of "1"
# $hash will hold hashtable, @{one="foo";two="bar";three="baz"}
[^_^]PS[20]>$str, $int, $hash = MultiReturn
[^_^]PS[21]>$str
Hi
[^_^]PS[22]>$int
1
[^_^]PS[23]>$hash
Name Value
---- -----
two bar
three baz
one foo
==============================