hmmk
hmmk

Reputation: 5

Convertto-html in Powershell outputting the wrong thing

I've been working on Powershell to extract data and I need to export the data I've gotten to an html file. It sounds simple because of the cmdlets, however its outputting the wrong thing.

My code is:

c:> get-servergroup | %{$_. Name + " " + $_.ServerOff + " " + $_.ServerOn} 

This then produces a small table below with the names and which servers are on and off. However when I add on the converting cmdlet like below:

c:> get-servergroup | %{$_. Name + " " + $_.ServerOff + " " + $_.ServerOn} | Convertto-html | Out-file Test.html

it gives me 3 values like * 35 62 So really, I just want to know if there's something wrong with the code? or if I'm missing something.

If the questions already been answered, then please just say!

Thank you!

Upvotes: 0

Views: 941

Answers (1)

manojlds
manojlds

Reputation: 301477

You probably want to do something like:

get-servergroup | Select Name,ServerOff,ServerOn | ConvertTo-Html | out-file test.html

Note that the previous one converted the objects into string ( objects ) and the convertto-html cmdlet produced the appropriate output.

Upvotes: 1

Related Questions