Working with third party methods

by Lery at 2013-04-15 13:12:20

I’m working with a third party vendor that I think is at least partially a .NET application. Therefore, I’ve found the COM object the third party has available. I know that you can pipe a WMI class to get-member. This will show you the properties and methods available. You can then go to MSDN and look up the documentation on those methods, so you can get the format for what you can do with the method. Working with a third party, with no documentation, I’m left to figure it out on my own. If my understanding is correct, properties let me see what a certain value is already set to. Methods let me do something.

To start, I’m doing something like this: $a = New-Object -ComObject NameofObject

Now I can do something like this: $a | gm

I’m not having any issue running it against the properties returned. It’s when I get to the methods, I get lost. I’m mostly using trial and error. So for example here are the methods available:

TypeName: System.__ComObject#{3c9e4500-07df-46ba-b575-c6be193a5993}

Name MemberType Definition
---- ---------- ----------
ClearMachineGuid Method void ClearMachineGuid ()
HasMaintenanceWindow Method int HasMaintenanceWindow (string)
IsInMaintenanceWindow Method int IsInMaintenanceWindow (string, string)
NextMaintenanceWindow Method string NextMaintenanceWindow (string, string)
NextMaintenanceWindow2 Method string NextMaintenanceWindow2 (string, string)
NotifyMaintenanceTask Method void NotifyMaintenanceTask (string, string, int, int, string, string)
PostAlertEvent Method void PostAlertEvent (string, string, string, string)
PostQueuedEvent Method void PostQueuedEvent (string, string)
PostQueuedEventFromFile Method void PostQueuedEventFromFile (string, string)
PutServer Method void PutServer (string, string)
ScheduleBasicInventory Method void ScheduleBasicInventory (int, int, int, int, int)
ScheduleUpdatePolicies Method void ScheduleUpdatePolicies (int, int, int, int)
SendBasicInventory Method void SendBasicInventory (int, int)
Start Method void Start ()
Stop Method void Stop ()
UpdatePolicies Method void UpdatePolicies (int)

Through some trial and error, I can run something like this: $a.Start() That happens to stop the third party vendors service. I can then use $a.Start() this should start the service but I get an error talking about the RPC server not being available. Which is not true, because I can go and manually start the third party vendors service without issue. This seems to be related to PowerShell. I can quit the PowerShell session and start it again. Then create the com-object, and run the Start command without issue.

If I take for example the SendBasicInventory method. This method says it’s definition is void SendBasicInventory (int, int). I think that means I can void the current value of 1 with whatever I want. I think it’s saying it must be in the format of a number only. So I run something like this $a.SendBasicInventory(1, 2) When I do this, nothing happens. I thought it worked, but it does not change the value in the third party application. When I try running $a.SendBasicInventory(2) I get an error saying:

Cannot find an overload for "SendBasicInventory" and the argument count: "1".
At line:1 char:27
+ $client.SendBasicInventory <<<< (2)
+ CategoryInfo : NotSpecified: (:slight_smile: , MethodException
+ FullyQualifiedErrorId : MethodCountCouldNotFindBest

So my question becomes this. When I have no documentation available to me, how can I figure out how to use these methods to do cool things :slight_smile: ?
by DonJ at 2013-04-15 15:06:41
Well, first, Get-Member can’t work as well for COM objects because they don’t support reflection, which is the magic that Get-Member relies on. COM objects provide a static TLB file, or they don’t; what Get-Member shows you is the best it can do after .NET creates an interop wrapper around the COM object.

The Start() method may rely on communications (RPCs) that aren’t needed for a manual start. PowerShell itself doesn’t use RPCs for anything, although some commands - such as Get-WmiObject - may do so. So that error is definitely coming from the COM component.

With COM objects, when you have no documentation available to you, you cry, drink a beer, and do something else. COM just isn’t built to be as self-discoverable as .NET is - that’s one of the big things .NET sought to solve, in fact.

So, your "SendBasicInventory" method requires two INTs, which is why you get an error when providing only one. Further, you’ve no idea what those numbers mean. They might be telling the method to work in a particular way, not replacing simple values (I actually doubt they’re just replacing simple values).

Again - with no docs, you’re blind, deaf, and quadriplegic. You have nothing to work with, nothing to go on.
by happysysadm at 2013-04-16 05:33:26
Hi Lery,

on the Net I found this:

Send Basic Inventory
SendIfUnchanged = 1 ’ or 0 if you don’t want to do this if is hasn’t changed
IgnoreBlockouts = 1 ’ or 0 if you don’t want to do this when blocked
NSAgent.SendBasicInventory SendIfUnchanged, IgnoreBlockouts

It refers to Altiris.

Apart from that it looks like you have no docs and, as Don said, no docs, nothing to go on…

Carlo
by Lery at 2013-04-16 06:38:48
Thanks Don and happysysadm. I found the vendor gives some VBS samples that I was able to figure out in PowerShell. Oddly enough the UpdatePolicies method requires only one integer. So I was able to use something like this:
$c = New-Object -ComObject Altiris.AeXClient
$c.UpdatePolicies(1)


I’ve contacted the vendor to see if they could supply me with any documentation so that I can figure out the rest.

Don, thank you for your explanation. It helped clarify things for me. Regarding the (Start), (Stop) methods. When I stop the service it seems to unbind, if that is the right terminology, the com object from the variable. The only way I could get it working is by doing this:

$c = New-Object -ComObject Altiris.AeXClient
$c.Stop()


$c = New-Object -ComObject Altiris.AeXClient
$c.Start()


That works. But just doing the $c.Start() or $c.Stop() does not. Go fish :slight_smile:
by DonJ at 2013-04-16 06:42:02
Not surprising. If you have a reference to a running piece of software, and you stop that software… it all goes away.