Powershell Output does not display when run on remote PC

I wrote a simple script to display installed programs. It works on the local machine just fine - grabs the programs, lists them alphabetically, great. When I try to run it on a remote PC, the script finishes but there is no output. No error, but nothing displayed. I tried putting Write-Host in various places, but no joy. I would like to be able to retrieve this information without having to write it to a file on the local machine, and then open the file to read the info. Any hints? Also not sure if the invoke-command is needed.


$Computername = Read-Host -prompt ("Which PC would you like to Inventory installed software on?")
$Credential = Read-Host -prompt ("What domain and username would you like to Authenticate with?")
$s = New-PSSession -ComputerName $Computername -Credential $Credential
Invoke-Command -Session $s -ScriptBlock {Get-WMIObject -Class Win32_Product -Computername $Computername | Sort name | Format-Wide -Column 1 -passthru}
Matthew EilersI.T. SpecialistAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
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:
As a rule of thumb, Format-* needs to be the last command in a pipe. This includes Invoke-Command output.
Using Invoke-Command -ComputerName together with Get-WMIObject -Computername is doing the same thing twice ;-). I would just do the WMI query:
$Computername = Read-Host -prompt ("Which PC would you like to Inventory installed software on?")
$Credential = Read-Host -prompt ("What domain and username would you like to Authenticate with?")
Get-WMIObject Win32_Product -Computername $Computername -Credential $Credential | Sort name | Format-Wide -Column 1 -passthru

Open in new window

will probably work much better.
0

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
footechCommented:
To add to Qlemo's post...
If you have firewall restrictions such that you can't do a direct query via Get-WmiObject, then you could either use Get-WmiObject (omitting the computername parameter) within the Invoke-Command scriptblock, or you could substitute Get-CimInstance for Get-WmiObject in the code Qlemo posted.

Caveat - I feel I have to post this almost every time I see use of Win32_Product.
https://gregramsey.net/2012/02/20/win32_product-is-evil/
People should be aware of the potential downside before using.
0
Matthew EilersI.T. SpecialistAuthor Commented:
Thank you for you input guys. Unfortunately -passthru is not being recognized as a usable parameter in this version.
0
Making Bulk Changes to Active Directory

Watch this video to see how easy it is to make mass changes to Active Directory from an external text file without using complicated scripts.

Matthew EilersI.T. SpecialistAuthor Commented:
Hah! However, removing the -passthru actually DOES return the programs I was hoping for in my terminal. Cheers!
0
Qlemo"Batchelor", Developer and EE Topic AdvisorCommented:
Correct, I should have removed that switch ...
0
PberSolutions ArchitectCommented:
No comment has been added to this question in more than 21 days, so it is now classified as abandoned.

I have recommended this question be closed as follows:

Split:
-- Qlemo (https:#a42429319)
-- footech (https:#a42429416)
-- Matthew Eilers (https:#a42430579)


If you feel this question should be closed differently, post an objection and the moderators will review all objections and close it as they feel fit. If no one objects, this question will be closed automatically the way described above.

Pber
Experts-Exchange Cleanup Volunteer
0
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.