In the last post, I showed you how to use PowerShell to connect to the Orchestrator COM interface for getting (and setting) various types of information. Now I’m going to run through a quick demo of how to get things like global resources (variables, counters, etc.) from COM and even modify them if you need to.
If you haven’t read the first post, go back and read it first because I won’t go over the connection process again here. I’ll assume you already know how to create a COM object and a connection handle, and I’ll just use the variable name $handle from here on out to represent that process.
The first thing to understand is that variables, counters, schedules, and computer groups are all “global resources” in Orchestrator. If you were looking through the methods available via the COM interface, this is probably why you were wondering if there was a way to access these things. These types of objects are all accessible through the GetResources, LoadResource, AddResource, and ModifyResource methods, but the method parameters might be a bit confusing until you know the structure. Since all of these different resource types are available via the same COM methods, they have to be differentiated in some way so Orchestrator knows what you want. This is done via a resource type ID and a parent folder ID.
If you wanted to get all instances of a specific type (like all variables), you would use the GetResources method like this:
You should already know how to get $Handle and the [ref]$outVar parameters, but how do you get the ResourceTypeID or the ParentID? I’ll make it easy for you. In my script, I create a hashtable, which amounts to an enum value that I can reuse by using a property name instead of having to cut and paste Guid values everywhere. Here’s how I do it:
Using the above, I can now specify $ResourceTypeID = $ResourceType.Variable inside my script and know I’ll always get it right. Or, I can use the hashtable values directly like this:
Formatting the XML for readability, here’s some sample output.
Now that you see the format of the XML, you’ll have the format required for the AddResource and ModifyResouce methods, and the resource id needed for the different methods can be seen in the UniqueID element of the XML. So, you should have the building blocks for all of the methods around the global resource objects! I will continue posting more of these examples as well as some sample script code shortly.