new-object -comobject

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

davesnbAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Qlemo"Batchelor", Developer and EE Topic AdvisorCommented:
Do you get anything?
new-object -comobject Egilh.ComTracker | gm

Open in new window

davesnbAuthor Commented:
No, that was my first line of code  . Blank result
Qlemo"Batchelor", Developer and EE Topic AdvisorCommented:
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.
Announcing the Winners!

The results are in for the 15th Annual Expert Awards! Congratulations to the winners, and thank you to everyone who participated in the nominations. We are so grateful for the valuable contributions experts make on a daily basis. Click to read more about this year’s recipients!

davesnbAuthor 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 AdvisorCommented:
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.
davesnbAuthor 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 .
Qlemo"Batchelor", Developer and EE Topic AdvisorCommented:
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).

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.