How to use PowerShell to access methods and proper

2019-05-17 10:39发布

问题:

I am trying to write a PowerShell script which could access methods and properties of a third-party OLE DLL.

The software vendor provided a working example in vbscript to achieve the same result. Below is an excerpt of the codes:

Set objOLE = CreateObject("NETIQOLE.APPMANAGER")
objOLE.Logon strInstance, strRepository, strUserID, strPwd
...

However, when I tried to code in PowerShell as below:

$objOLE = New-Object -ComObject "NETIQOLE.APPMANAGER"
$objOLE | Get-Member

I got output below and didn't see any relevant method or property.

   TypeName: System.__ComObject

Name                      MemberType Definition                                                     
----                      ---------- ----------                                                     
CreateObjRef              Method     System.Runtime.Remoting.ObjRef CreateObjRef(type requestedType)
Equals                    Method     bool Equals(System.Object obj)                                 
GetHashCode               Method     int GetHashCode()                                              
GetLifetimeService        Method     System.Object GetLifetimeService()                             
GetType                   Method     type GetType()                                                 
InitializeLifetimeService Method     System.Object InitializeLifetimeService()                      
ToString                  Method     string ToString() 

Is there anything I can do to access to this OLE Dll's methods and proerties? Any advice or sample codes are welcome. Thank you in advance.

回答1:

Thank you both for your kind responses. The link given by @Ekkehard.Horner worked. It really save my day.

The working codes are now:

$credential = "...", "...", "...", "..."
[System.__ComObject].InvokeMember("Logon", [System.Reflection.BindingFlags]::InvokeMethod, $null, $netiqObj, $credential)