• Status: Solved
  • Priority: Low
  • Security: Public
  • Views: 39
  • Last Modified:

hepl with PS output.

I have a small script that  uses powercli to get some info (tool version) and it works just fine. The output is messy. Here is the script:
#this gets the client and host versions of the vmware tool
New-VIProperty -Name ToolsVersion -ObjectType VirtualMachine -ValueFromExtensionProperty 'Config.tools.ToolsVersion' -Force
New-VIProperty -Name ToolsVersionStatus -ObjectType VirtualMachine -ValueFromExtensionProperty 'Guest.ToolsVersionStatus'-Force
$ServerListFile = ".\servers.txt" 
$ServerList = Get-Content $ServerListFile -ErrorAction SilentlyContinue
$Result = @()
ForEach($computername in $ServerList)
{
Get-VM -name $computername | Select Name, Version, ToolsVersion, ToolsVersionStatus|ft -auto
}

Open in new window


The output looks like this:
Name           Version ToolsVersion ToolsVersionStatus
----           ------- ------------ ------------------
server     v11        10282 guestToolsCurrent

Name           Version ToolsVersion ToolsVersionStatus
----           ------- ------------ ------------------
server2     v11        10282 guestToolsCurrent

Name           Version ToolsVersion ToolsVersionStatus
----           ------- ------------ ------------------
server3     v11        10282 guestToolsCurrent

Open in new window


I'd like it to be :
Name        Version ToolsVersion ToolsVersionStatus
----              -------      ------------         ------------------
server1     v11        10282              guestToolsCurrent
server2     v11        10282              guestToolsCurrent
server3     v11        10282              guestToolsCurrent

[

Open in new window


The formatting in this post isn't what I'd like, but I think you see what I mean.

thx!!
~Jahn
0
SquigglyMonkey
Asked:
SquigglyMonkey
  • 3
1 Solution
 
oBdACommented:
You're sending single formatted object to the pipeline.
Try it like this:
#this gets the client and host versions of the vmware tool
New-VIProperty -Name ToolsVersion -ObjectType VirtualMachine -ValueFromExtensionProperty 'Config.tools.ToolsVersion' -Force
New-VIProperty -Name ToolsVersionStatus -ObjectType VirtualMachine -ValueFromExtensionProperty 'Guest.ToolsVersionStatus'-Force
$ServerListFile = ".\servers.txt" 
$ServerList = Get-Content -Path $ServerListFile -ErrorAction SilentlyContinue
$ServerList | ForEach-Object {
	Get-VM -Name $_ | Select Name, Version, ToolsVersion, ToolsVersionStatus
} | Format-Table -AutoSize

Open in new window

1
 
SquigglyMonkeyAuthor Commented:
Thank you that works perfectly.
0
 
SquigglyMonkeyAuthor Commented:
adding this seems to be the main thing.
$Result = @()
1
 
Senior IT System EngineerIT ProfessionalCommented:
So where do you add the $Result = @() ?
0
 
SquigglyMonkeyAuthor Commented:
I was having a rough day, and wrote that incorrectly.
What I should have written was removing $Result = @() and then piping $serverlist into foreach-object

$Result = @()
ForEach($computername in $ServerList)

Open in new window

became
$ServerList | ForEach-Object 

Open in new window


Very sorry about the confusion.
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.

Join & Write a Comment

Featured Post

Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now