Friday, October 3, 2008

"Include" in Powershell

Powershell isn't like a fully-fledged programming language - it's still designed to be a shell and a little more accessible to the average user. That doesn't mean that you can't do many of the things you are able to do in Java or C#.

A handy trick I found out is including other PowerShell files with functions in them as part of a library. All it takes is a period (.) followed by a space ( ) and the full path to the ps1 file. Any functions you put in there will automatically be included in your new PowerShell script. I wrote a function that takes a String (a SELECT statement) and returns a PSObject representing the statement I just gave it.

This can be handy in Documentum so that you don't need to copy large amounts of text into your scripts: you just need to include the library. I have written them for sending messages, running SQL queries, and updating Documentum.

Recently, I learned how to create a .NET link to Documentum in PowerShell. PowerShell isn't handling the errors very well yet, but I may be able to get it some error trapping that means it doesn't crash when it tries to load a program. That will have to wait for another post, however, as I'm on my way home for the weekend.