Voodoo PowerShell – VisioBot3000 Lives Again!

Back in January I wrote a post about how VisioBot3000 had been broken for a while, and my attempts to debug and/or diagnose the problem.

In the process of developing a minimal example that illustrated the “breakage”, I noticed that accessing certain Visio object properties caused the code to work, even if the values of those properties were not used at all.

It’s been almost six months now, and I have no idea why that code makes any difference. So instead of letting VisioBot3000 die, I decided to take the easy route, and incorporate the “nonsense” code in the VisioBot3000 module.

If you look at the latest commit (as of this writing), the New-VisioContainer function (in VisioContainer.ps1) starts with the following single line of nonsense:

[void]$script:Visio.ActiveDocument.Pages[1]

In that code, I’m using a module-level reference to the Visio application, getting the active document from it, and retrieving the first page. And then I’m throwing away the reference that I just retrieved. The only thing that I can imagine is doing anything is the Pages[1] call. It’s possible that the COM object is doing something internally in addition to pulling back the first page, but that’s grasping at straws.

And that’s why I call this Voodoo PowerShell. I’m using code that I don’t understand because I get what I want from it. It’s a meaningless ritual. I hate including it, but I hate that the module has been largely unchanged for a year even worse.

I will be trying to make more regular updates to VisioBot3000 in the near future, and will be presenting on it at the second SWMO PSUG meeting scheduled for next week.

Let me know what your thoughts are.

–Mike