Saturday, January 19, 2008

Dctm-PoSh Integration - Chapter 1

December 17, 2006 - I get a new job at a company in IT for the first time in my life. My official position? "That Documentum Guy." What is Documentum, you might ask? Only one of the most sophisticated pieces of software out there for document management. It is produced by EMC Corp. My job? Make document management happen at my company. And how much Documentum experience had I had? Well, I'd never heard of Documentum. It was going to be a challenge.

Any sysadmin is going to want to be able to effect change on huge amounts of files, programmatically. And how much programming experience had I had? Very little. Batch file programming was my specialty. I remember when I was about 12 making a batch file menu, that would boot the computer with certain options for certain environments that I needed. So, I started out writing Documentum scripts in batch files. Not very scalable, and certainly not very easy.

That's when I discovered PowerShell (PoSH), Microsoft's new command line environment built on the .NET framework. The main difference between PoSH and batch files is that PoSH is object-oriented, not procedural. The main advantage when dealing with scripting Documentum, however, was the ability to write much more complicated logic, such as FOR statements, FOREACH statements, and embedding such statements within each other. I called the project of getting PowerShell to talk to Documentum Big Thunder Mountain, after one of my favourite rides at Disneyland. I wrote the first PoSH script in July of 2007. It wasn't very advanced - all it did was take a look at people's default folder, see if there was a folder in there marked Private, and create one if it didn't exist. I had to teach myself some stuff about parsing text files, and stage one was complete. I was now able to write rudimentary files for connecting to a docbase.

Details of the First Script

I realized early on that I would be writing more than one Big Thunder Mountain script, so I developed three lines of code that would run SELECT statements in Documentum:
echo "select $sourcecolumn from ""dm_folder"" where folder ('/Cabinet/Home Folders')" set-content -path c:\test\run.txt
echo "go" add-content -path c:\test\run.txt
cmd /c c:\test\1.bat c:\test\folders.txt
[1.bat was a batch file I wrote for running idql32.exe, as I couldn't figure out how to pass the correct arguments from PowerShell to the program. More on that later]

PowerShell requires that all variables begin with a dollar sign, so $sourcecolumn was the name of the column I was going to select from the database. In this case, I was looking for object_name.

The next few lines parsed the text file output, and put them into a text file, then loaded them into an object:
findstr /v "$sourcecolumn ---------------" c:\test\folders.txt > c:\test\temp.txt
findstr /v "affected" c:\test\temp.txt > c:\test\folders.txt
remove-item c:\test\temp.txt
$folders = get-content c:\test\folders.txt

At this point I was still using findstr.exe from the old Command Prompt days. Those days, however, were soon to end.

The next few lines included a couple FOREACH statements, designed to go through each folder and see if there was a folder called Private. If there wasn't, it wrote the name of the person to a text file (one text file per person - a horrible way to do administration). If there was, it did not include the person.
foreach ($folder in $folders){$folder = $folder.TrimEnd()
echo "select $sourcecolumn from ""dm_folder"" where folder ('/Cabinet/Home Folders/$folder')" set-content -path c:\test\run.txt
echo "go" add-content -path
c:\test\run.txtcmd /c c:\test\1.bat "c:\test\$folder.usr"
$userfolder = get-content "c:\test\$folder.usr"
foreach ($item in $userfolder){$item = $item.TrimEnd()if ($item -eq "Private")
{remove-item "c:\test\$folder.usr"}}}
get-childitem c:\test\*.usr set-content -path c:\test\noprivate.txt
remove-item c:\test\*.usr

Wow, I am so embarrassed by this script now. I realize now how little I know both about DQL statements and PoSH. As we'll see in the next installment, I learned some tricks.

Thursday, December 27, 2007

New Blog

You know, before, I think I only thought I knew what I was thinking. This whole internet fad was still pretty new - almost like it was RC2 or something. Definitely not the Web 2.0 we have now. In 2001, I set up a website when I proposed to a wonderful Canadian woman. I definitely haven't looked back as far as the relationship was concerned, but I sure have learned some things with respect to privacy and social networking.

It came out a week or so ago on slashdot that scamming people on social networking sites is the biggest scam of 2007. So, I am moving the personal content of this blog into a private, unlisted blog. If you have the internet address for the original website, you can still visit it. However, spiders and the like will not be scouring my personal pictures anymore. I also recently started using Facebook. Yay. What an efficient way to waste time that is.

That being said, I did still have dreams of being famous for doing nothing other than publish my thoughts. Personal life was out, so I thought I'd go to my work. I do think about work a lot, and Powershell blogs seem pretty common, so here we go. I am our company's Documentum guy. No one knows it in our company like I do (I still don't know anything, but that's beside the point). For the past 6 months or so, I have been bending Powershell and Documentum together, so I thought I would share that information with the one person who might ever need it. As far as I know, I am the only person using Powershell to automate tasks in Documentum. If anyone else has done it, please let me know, so I can stop being so cocky.

I know what you're thinking. "What does this have to do with me?"

Answer: "If you came here thinking you would get personal information about David Meredith, you'll have to go elsewhere. If you don't know where to go, ask David. If he doesn't let you know where to go, you know where to go.

"If you came here because you thought, 'Documentum and Powershell, that sounds hecka fun!' then you came to the right place. You and I are being shipped to the loony bin Monday morning."

Let's hear it for frequently updated blogs! Yay!