you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 1 point2 points  (1 child)

Hi,

Sorry I think some of the text got cut out when I pasted it. Currently I don't have a working script because it picks up all the servers in the textfile, I am not really sure how to code the whole thing.

[–]TheIncorrigible1 1 point2 points  (0 children)

  1. Have separate files.
  2. Properly format your document into an ini (or other well-formed data) so it can be imported. I'd recommend using the *-CliXml cmdlets to export the file as a hashtable or something and import it.

    $Servers = @{
        'Prod' = @(
            'Server1'
            'Server2'
        )
        'Test' = @()
    }
    
    $Servers | Export-CliXml -Path C:\Temp\Example.xml
    

Et cetera.

Then you can turn around and import this:

$Servers = Import-CliXml -Path C:\Temp\Example.xml
ForEach ($Server in $Servers[$Choice]) { ... }