If you wanted to get all instances of a specific type (like all variables), you would use the GetResources method like this:
$retval = $oismgr.GetResources($Handle, $ParentID, $ResourceTypeID, [ref]$outVar)
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:
$ResourceType = @{}
$ResourceType.Variable = "{2E88BB5A-62F9-482E-84B0-4D963C987231}"
$ResourceType.Counter = "{0BABBCF6-C702-4F02-9BA6-BAB75983A06A}"
$ResourceType.Schedule = "{4386DA28-C311-4A2B-8C47-3C7BB9D66B51}"
$ResourceType.Computer = "{162204B6-7F54-4CB9-A678-B94A6510BD0C}"
$ResourceFolderRoot = @{}
$ResourceFolderRoot.Runbooks = "{00000000-0000-0000-0000-000000000000}"
$ResourceFolderRoot.Variables = "{00000000-0000-0000-0000-000000000005}"
$ResourceFolderRoot.Counters = "{00000000-0000-0000-0000-000000000004}"
$ResourceFolderRoot.Computers = "{00000000-0000-0000-0000-000000000001}"
$ResourceFolderRoot.Schedules = "{00000000-0000-0000-0000-000000000006}"
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:
$retval = $oismgr.GetResources($Handle, $ResourceFolderRoot.Variables, $ResourceType.Variable, [ref]$outVar)
Formatting the XML for readability, here’s some sample output.
<Objects>
<Object>
<UniqueID datatype="string">{70DBD127-47FC-487C-BCAA-4E60BC755EFA}</UniqueID>
<Name datatype="string">Max Counter</Name>
<Description datatype="null">
</Description>
<ObjectType datatype="string">{2E88BB5A-62F9-482E-84B0-4D963C987231}</ObjectType>
<SubType datatype="null"></SubType>
<Enabled datatype="bool">FALSE</Enabled>
<Flags="" datatype="null">
</Flags>
<ASC_UseServiceSecurity datatype="null"></ASC_UseServiceSecurity>
<ASC_ThisAccount datatype="null"></ASC_ThisAccount>
<ASC_Username datatype="null"></ASC_Username>
<ASC_Password datatype="null"></ASC_Password>
<AlternateDisplayData datatype="null"></AlternateDisplayData>
<ASW_ObjectTimeout datatype="null">
</ASW_ObjectTimeout>
<ASW_NotifyOnFail datatype="null"></ASW_NotifyOnFail>
<Flatten datatype="null"></Flatten>
<FlatUseLineBreak datatype="null"></FlatUseLineBreak>
<FlatUseCSV data=""type="null"></FlatUseCSV>
<FlatUseCustomSep datatype="null"></FlatUseCustomSep>
<FlatCustomSep datatype="null"></FlatCustomSep>
<ObjectTypeName datatype="string">
Variable
</ObjectTypeName>
<Type datatype="null"></Type>
<Value datatype="string">3</Value>
</Object>
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.