new-object -comobject

davesnb
davesnb used Ask the Experts™
on
Hello EE,

I had a script runing under 2003 server and  powershell using the below com object , however when i run the getstatistics nothing comes back , the object is registered and the Egilh.ComTracker shows in the com object list . Is there a way to get this working under the 2012 64bit whcih I am running now?

$tracker = new-object -comobject Egilh.ComTracker
$trackerlist = [xml]($tracker.getstatistics())

Open in new window



 Get-ChildItem HKLM:\Software\Classes -ErrorAction SilentlyContinue | Where-Object {
   $_.PSChildName -match '^\w+\.\w+$' -and (Test-Path -Path "$($_.PSPath)\CLSID")
} | Select-Object -ExpandProperty PSChildName

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Qlemo"Batchelor", Developer and EE Topic Advisor
Top Expert 2015

Commented:
Do you get anything?
new-object -comobject Egilh.ComTracker | gm

Open in new window

Author

Commented:
No, that was my first line of code  . Blank result
Qlemo"Batchelor", Developer and EE Topic Advisor
Top Expert 2015
Commented:
Then the COM object does not work, probably because of the 64bit OS. Make sure you use the 32bit PowerShell, the default is to use the 64bit one.
Expert Spotlight: Joe Anderson (DatabaseMX)

We’ve posted a new Expert Spotlight!  Joe Anderson (DatabaseMX) has been on Experts Exchange since 2006. Learn more about this database architect, guitar aficionado, and Microsoft MVP.

Author

Commented:
OK It works when I run the 32 bit powershell version . However, in my case I have a script that runs on a powershell ssh session , so I need to force the script to run as 32bit . Is there a way to include something at the beginning of the script to run using 32bit powershell?
Qlemo"Batchelor", Developer and EE Topic Advisor
Top Expert 2015

Commented:
How do you connect exactly? When creating a remote PS session via WinRM you can provide a session configuration created for that purpose of making sure you run on 32bit.

Author

Commented:
I connect using "powershell server " it runs as a service . So when I connect , it connects to the native shell, which in this case is 64 bit .
"Batchelor", Developer and EE Topic Advisor
Top Expert 2015
Commented:
You need to be able to set the configuration name for the PSSession. http://www.powershellserver.com/powershell-server-executing-scripts-in-an-x86-runspace/ says you can't, so start 32bit commands in the existing session with
Invoke-Command -ConfigurationName Microsoft.PowerShell32 -ComputerName localhost -ScriptBlock {
  $tracker = new-object -comobject Egilh.ComTracker
  $trackerlist = [xml]($tracker.getstatistics())
}

Open in new window

The suggested code in the link is cumbersome and non-generic, but has the pro that is does not use WinRM. It starts a new PS process with the script (but requires a script).

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial