Wednesday, January 7, 2009

Verify PSSnapin (Script vs PrimalForms)

When running a script from the console or the various IDE's, you can check for a specific snap-in with the #requires statement. See ALEKSANDAR's blog post for the complete description.

When running a script as a winform (like through PrimalForms), you may need to attack from a different angle. It may be necessary to capture the fact that a particular snap-in is not installed and present it in the GUI or a messagebox. For this the following may be a better approach:
$snapin = "Quest.ActiveRoles.ADManagement"
if ((get-pssnapin -name $snapin -erroraction silentlycontinue) -eq $null)
$statusBar1.text =
"$snapin is not installed"

No comments: