i need to figure out how to save info from a PowerShell script as a text file

I have a PowerShell script that lists all servers in my domain.   I need to have this information put into another PowerShell script as seen below in the "servers names" box.  

New-Item -Path  HKLM:\Software\Microsoft\Windows\CurrentVersion\EventCollector\Subscriptions\taco\EventSources -Name "servers names" –Force

This script creates a folder under eventsources in the registry called "server name".   This folder is how event collector (log server) creates subscriptions of servers.   so if I have a server named burrito.   event subscription will add that server "burrito" to its event collector subscription to gather logs.  I need PowerShell to read the servers I collected and put them in the "server names" part of the above script so that those folders are created.   I hope this makes sense.
gmckfnAsked:
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.

Mauro CazabonnetSenior Software EngineerCommented:
Looking for something like this?

$servers = @("Server1","Server2","Server3","Server4")

foreach ($server in $servers){
    New-Item -Path  HKLM:\Software\Microsoft\Windows\CurrentVersion\EventCollector\Subscriptions\taco\EventSources -Name $server –Force
}

Open in new window

0
gmckfnAuthor Commented:
Kinda.    I used this:

Get-ADComputer -Filter {OperatingSystem -Like "Windows Server*"} | Select -expandProperty Name  

to get the names of my servers in AD... since some servers may change I have it running as a task to pick up new servers.   so say I have a list that comes back with taco, burrito and chips as my servers.   how do I get that list into your scipt above in the $servers = @ ("server1" , "server2"...... without typing them manually???
0
Mauro CazabonnetSenior Software EngineerCommented:
Ah ok :)
Import-Module ActiveDirectory
$servers = Get-ADComputer -Filter {OperatingSystem -Like "Windows Server*"} | Select -expandProperty Name  
foreach ($server in $servers){
    New-Item -Path  HKLM:\Software\Microsoft\Windows\CurrentVersion\EventCollector\Subscriptions\taco\EventSources -Name $server –Force
}

Open in new window

1

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
gmckfnAuthor Commented:
That did it... you rock!   looks my my next class will be powershell :)
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.