write-host: append variables in one line, comma separated

rated by 0 users
This post has 2 Replies | 2 Followers

Not Ranked
Posts 3
general_issimo Posted: 05-15-2012 10:51 AM

Hey Guys,

I am pretty novice with powershell and having some trouble with my latest script.

Basically, it should do nothing more than gather some data from a local machine and append it to a textfile.

In the output-file, I'd like to have one line per computer and list the gathered info separated by commas.

e.g.:

computername1,00:00:00:00:00:00

computername2,00:00:00:00:00:01

computername3,00:00:00:00:00:02

 

I've tried several stuff but i am stuck here. Instead of writing in one line separated by commas, the only somewhat-useful output i can get looks like this:

computername1

00:00:00:00:00:00

computername2

00:00:00:00:00:01

computername3

00:00:00:00:00:02

 

Anyone having a hint for me?

Thanks a lot!

 

The script looks like this (I plan to add some more values, later):

###########

$cs = Get-WmiObject -Query "Select * from Win32_Computersystem"
write-host "Hostname        : " $cs.Name

#$ComputerName = gc env:computername
$nw = Get-WmiObject Win32_NetworkAdapterConfiguration -ComputerName $cs.Name | ? {$_.IPEnabled}
write-host "Mac Address     : " $nw.MACAddress

write-host "."

write-host $cs.Name,$nw.MACAddress
write-output $cs.Name,$nw.MACAddress | out-file D:\outfile.txt -append

################

Top 25 Contributor
Posts 281
Top Contributor

"{0},{1}" -f  $cs.Name,$nw.MACAddress | out-file D:\outfile.txt -append

Not Ranked
Posts 3

This is exactly what I was looking for. Thanks Dude, you made my day!

Page 1 of 1 (3 items) | RSS
Copyright 2012 PowerShell.com. All rights reserved.