powershell output question

I have a little script to check the version of SEP on some systems. It works,outputs the name and the version. The problem is it puts the "headers" on each server.
$servers = gc servers.txt
foreach ($server in $servers)
{Invoke-Command -ComputerName $server -Command {Get-ItemProperty -Path "HKLM:SOFTWARE\\Symantec\
\Symantec Endpoint Protection\currentversion"}|ft pscomputername, productversion}

Open in new window



The output looks like this:
PSComputerName PRODUCTVERSION
-------------- --------------
server1        14.0.3752.1000



PSComputerName PRODUCTVERSION
-------------- --------------
server2        14.0.3752.1000

Open in new window

Can I easily get it to look like this:
PSComputerName PRODUCTVERSION
-------------- --------------
server1        14.0.3752.1000
server2        14.0.3752.1000

Open in new window


Thx!
LVL 1
SquigglyMonkeyAsked:
Who is Participating?
 
Jason CrawfordTransport NinjaCommented:
Try this:

Invoke-Command -ComputerName (Get-Content .\servers.txt) -ScriptBlock {
    Get-ItemProperty -Path 'HKLM:SOFTWARE\\Symantec\\Symantec Endpoint Protection\currentversion' | Select-Object pscomputername,productversion
}

Open in new window

The benefit to ditching the foreach is the command will fan out concurrently on all servers instead of one at a time with the foreach.
0
 
SquigglyMonkeyAuthor Commented:
Thanks for the response, that's super close to what I'd like it to look like.  The prodcutversion shows up first, and something was added that is not listed at all (runspaceid?)
PRODUCTVERSION PSComputerName RunspaceId
-------------- -------------- ----------
14.0.3752.1000 server1    5190bc88-67b5a09fdd
14.0.3752.1000 server2     fc8d9e89e70b59

Open in new window

0
 
SquigglyMonkeyAuthor Commented:
I piped it out to ft, and the runspaceid is gone, and the server name is first, thank you!!

The end result or anyone that wants it is:
Invoke-Command -ComputerName (Get-Content .\servers.txt) -ScriptBlock 
{Get-ItemProperty -Path 'HKLM:SOFTWARE\\Symantec\\Symantec Endpoint Protection\currentversion' | 
Select-Object pscomputername, productversion
}|ft pscomputername, productversion

Open in new window

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.

 
Jason CrawfordTransport NinjaCommented:
That is weird.  Maybe try rebooting haha kidding.

Maybe try a PSObject:

Invoke-Command -ComputerName (Get-Content .\servers.txt) -ScriptBlock {
    $item = Get-ItemProperty -Path 'HKLM:SOFTWARE\\Symantec\\Symantec Endpoint Protection\currentversion'
    [array]$results += New-Object -TypeName PSObject -Property @{
        'Computer Name' = $item.pscomputername
        'Product Version' = $item.productversion
    }
    $results
}

Open in new window

0
 
Jason CrawfordTransport NinjaCommented:
Glad I could help.  If my solution was correct please mark it as the answer instead of closing the question.  Take care :)
0
 
SquigglyMonkeyAuthor Commented:
I don't think the guy who answered is getting the points he deserves.
0
 
SquigglyMonkeyAuthor Commented:
I canceled the first time I chose your answer as the best solution, I chose your answer as the best solution and this is the same thing that happened the first time.
1
 
Jason CrawfordTransport NinjaCommented:
It's weird I know.  You're not the first and you won't be the last.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.