Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

Getting console output into a file

$
0
0

Hi folks, i'm a new PS user. I've written this script up to record the # of servers starting with '0' thru whatever count the user enters and further on record the server names from user input. Now this script works well, but i'm not able to get the output to be appended to an existing config file, which also has existing data in it. I basically want to add the output into the serverclass.conf file at the very bottom (it's a plain text file). I tried to pipe it via "| out-file -filepath c:\serverconfig\serverclass.conf -append" but it does not work. Is there a better way to write this script out? Thanks a bunch

 

Write-Host="How many servers are being added to whitelist"

$servercount=Read-Host">>"

 

Write-Host"Enter server names separated with commas (no space)"

$serverListInput=Read-Host">>"

$serverList=$serverListInput.Trim().Split(',')

 

$serverclass="c:\serverconfig\serverclass.conf"

 

for($i=0;$i-lt $servercount; $i++)

{

   write-host:"whitelist.$i"'='$serverList[$i]

    }

 

OUTPUT to console after being prompted with the two "write host" statements above. I entered '3' for first query, and 'server1288,server1230,server1235' for second query. Final output below, which is what i needed to have inserted into the serverclass.conf file only.

: whitelist.0 = server1288

: whitelist.1 = server1230

: whitelist.2 = server1235

 


Viewing all articles
Browse latest Browse all 6937

Trending Articles