Paul Roub

A Software Tool Geek in His Natural Habitat

Creating Fortress Work Items From the PowerShell Command Line

Thought I’d pass on another PowerShell script I’ve been playing with. As before, this is bare-bones – exception handling, usage, help are all missing. But it’s doing what I need it to do this morning.

Again, we’re using the Fortress Client Integration library, but this time it’s a standalone script that you run explcitily. In this case, we’re creating simple Fortress Work Items.

The same caveats apply as before – run vault.exe’s REMEMBERLOGIN command at least once before using this script. You’ll also need to know the name of the Fortress project you’re adding to (the actual name as displayed, no internal ID numbers, etc are neeed).

The script wants the project name, and a description of the bug being added. Quote them if spaces are involved. We’ll default the rest of the fields, using values that are present in any new Fortress installation.

Feel free to test this out against, by the way. To add to the single project living there, you’d say:

AddFortressItem "Fortress Demo" "Just testing PowerShell, nothing to see here"

Save the following script somewhere in your PoSH path, and name it AddFortressItem.ps1

# AddFortressItem.ps1
# usage: AddFortressItem "Project Name" "Bug summary"

# Paul Roub <>

param (
        $projectName = $(throw "Please specify the project name"),
        $subject = $(throw "Please specify the bug description")

if (! $sgLoggedIn)
        if (! $sgLoaded)
                #  at start up -- attempt to load the Vault lib and log in
                #  Vault users -- change "Fortress Client" below to "Vault Client"
                [void] [System.Reflection.Assembly]::LoadFrom(
                        $ENV:ProgramFiles + 
                        '\SourceGear\Fortress Client\VaultClientIntegrationLib.dll')
                $sgLoaded = $true

        #  Log in based on previously-saved (via vault.exe) credentials.  
        #  Will attach to the previously-selected repository
                "Client", $true, $true)
        $sgLoggedIn = $true

$newitem = New-Object "VaultClientIntegrationLib.FortressItemExpanded"

#       use the project name and subject from the command line,
#       default the rest
$newitem.ProjectName  = $projectName
$newitem.Description  = $subject
$newitem.Details      = $subject
$newitem.ItemType     = "Bug"
$newitem.Status       = "Open"
$newitem.Platform     = "Unknown"
$newitem.TimeEstimate = "Unknown"
$newitem.Priority     = "Unknown"

#       check the item and get it ready to add

$res = [VaultClientIntegrationLib.ItemTrackingOperations]::ProcessCommandAddFortressItem(

echo "Added item:" $res.GetMantisItem().ID