More fun with Powershell
September 11, 2009
I was recently working on porting some existing ClearBasic batch (cbbatch) scripts to PowerShell. I’ve blogged in the past about using our SDK with Powershell. For this particular project, I had multiple scripts to port, and I was looking to extract some common functions and utilities, so that they could be used between multiple scripts. Configuration When using the Dovetail SDK, one of the first tasks is to load up the configuration information and connect to the database. That would normally look something like: $connectionString = “Data Source=localhost;Initial Catalog=dovetail;uid=user;pwd=pass" $databaseType = “MSSQL”; [system.reflection.assembly]::LoadWithPartialName("fcsdk") > $null; [system.reflection.assembly]::LoadWithPartialName("FChoice.Toolkits.Clarify") > $null; $config = new-object -typename System.Collections.Specialized.NameValueCollection; $config.Add("fchoice.connectionstring",$connectionString); $config.Add("fchoice.dbtype",$databaseType); $config.Add("fchoice.disableloginfromfcapp", "false"); $config.Add("fchoice.nocachefile", "true"); #Create and initialize the clarifyApplication object $ClarifyApplication = [Fchoice.Foundation.Clarify.ClarifyApplication]; if ($ClarifyApplication::IsInitialized -eq $false ){ $ClarifyApplication::initialize($config) > $null; } Code for re-use I didn’t want to repeat that in multiple scripts,…