FreeFlow, the .NET toolkit for Metastorm BPM

Home | Administrator | FAQ | Screenshots | Documentation | Downloads | Suggestions | Bugs | PowerShell | Links

PowerShell is a scripting language primarily aimed at system administrators. It provides full access to the .NET Framework and any other .NET assemblies.

Using PowerShell and the FreeFlow toolkit it is possible to write scripts to automate many administrative tasks that are typically done manually via one of the Metastorm administrative tools. As an example, here is a simple script that adds a new user, assigns a random password and then emails these details to the user.
        # check the right number of parameters were passed
        if ($args.Length -lt 2)
        {
          write-host "Usage : AddUser.ps1 userName emailAddress"
        }
        else
        {
          # load the required assemblies
          [Reflection.Assembly]::LoadFrom("C:\FreeFlow\FreeFlow.Administration.dll")
          [Reflection.Assembly]::LoadWithPartialName("System.Net")

          # connect to the database
          $server = New-Object FreeFlow.Administration.Server
          $server.Connect("sa","","Metastorm")

          # add the user
          $newUser = $server.Users.Add($args[0])
          if ($newUser)
          {
            $password = $newUser.SetRandomPassword(8)
            $newUser.EmailAddress = $args[1]
            $newUser.ApplyChanges()

            # send an email to the user
            $msg = New-Object System.Net.Mail.MailMessage
            $msg.From = New-Object System.Net.Mail.MailAddress("mail@somewhere.com")
            $msg.To.Add($args[1])
            $msg.Subject = "Metastorm BPM login details"
            $msg.Body = "Hi, your login is " + $args[0] + ", your password is " + $password
            $smtp = New-Object System.Net.Mail.SmtpClient("localhost")
            $smtp.Send($msg)
          }
        }
      
To call this script from the PowerShell console, use the following (assuming the script is stored in the same folder that PowerShell is running from and you've saved the sript as AddUser.ps1) -
        .\AddUser.ps1 userName emailAddress
      
If you're having trouble running PowerShell scripts, be sure to read this article that describes the changes you'll need to make to the PowerShell environment to get them running.