I am sure this is obvious but for the life of me I can not find the information. Many postings on splitting output to multiple lines, but I can't find information on using Multiple lines as input.
I often create text files with lists of variables then use $servers=GC servers.txt and use a "For each" loop to process them. There has to be a way to just include that list in the script.
For example if I normally create a 'servers.txt' consisting of:
server1
server2
server3....
Is it possible to list those server in the script it self. Something like (and I know this doesn't work as writen:
$servers= @(
Server1
Server2
Server3
)
UPDATE
I know I could separate them in to quotes and add commas but that is specifically what I am trying to avoid. If I copy a list of servers from a spread sheet with right click copy, I'd like to be able to paste it in my script without having to add commas and single quotes. Right now I avoid this by dumping the contents in to a text file then use Get-Content to import it, but I am trying to find a way to bypass that extra step and just be able to paste it in the script then click run without having to alter the text.
gcwhich is an alias forGet-Contentby default reads in a line of text as an array item. To create an equivalent, you just need to use array creation syntax -->$servers = 'server1','server2','server3'. The real question would be how isservers.txtgetting populated and is that feasible to have that data generated within a script? Ifservers.txtis automated by another process, then your main script potentially never needs to be changed as it can read a dynamic file. So either way could be beneficial.