PowerShell Scrip to add Data to Output Stream

In this question, I got the answer I needed (to some extent). The answer just output the data to the console, but I want to save it to a file. I originally tried export-csv but that produced a header row, which I do not want, so I started searching the web for ways to remove it. What I have now, and it works, is:
$RootFolder = "c:\temp"
$IncludeFiles = "*.properties"
$Pattern = "\A\s*[^#]?\s*insertonly\s*=\s*(.+)\Z"
(Get-ChildItem -Path $RootFolder -Include $IncludeFiles -Recurse |
	Select-String -Pattern $Pattern |
	Select-Object -Property Path | ? {$_.InsertOnly -ne "true"} | 
	ConvertTo-Csv -NoTypeInformation) | Select-Object -Skip 1 | Set-Content -Path C:\temp\insertonly.log 

Open in new window

However, I want to add the computer name to the output stream, using $ComputerName = [System.Net.Dns]::GetHostName() at the top of the script to get the computer name (the script is going to iterate through a collection of servers, so I want the server name as part of the output). Currently the output stream is:
"path to offending file"
I want it to be (note quoted values, comma separated):
"computername","path to offending file"

I've tried putting $ComputerName in the stream above in various places (as basically a literal value in the output--"$ComputerName" andunquoted) but keep getting errors. I'm sure it is a simple (probably very simple) addition to the code, but I don't know how to do it.
LVL 15
dbbishopAsked:
Who is Participating?
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.

footechCommented:
This should work for you.  It adds a calculated property with the Select-Object statement.
$ComputerName = [System.Net.Dns]::GetHostName() 
$RootFolder = "c:\temp"
$IncludeFiles = "*.properties"
$Pattern = "\A\s*[^#]?\s*insertonly\s*=\s*(.+)\Z"
(Get-ChildItem -Path $RootFolder -Include $IncludeFiles -Recurse |
	Select-String -Pattern $Pattern |
	Select-Object -Property @{n="ComputerName";e={$ComputerName}},Path | ? {$_.InsertOnly -ne "true"} | 
	ConvertTo-Csv -NoTypeInformation) | Select-Object -Skip 1 | Set-Content -Path C:\temp\insertonly.log 

Open in new window

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
dbbishopAuthor Commented:
Not only should it work, it does work! :-)
Thanks
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.

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.