Powershell GUI box to array

If I have this in a box
Server1
Server2
Server3

Open in new window



The text box is named: ServerList

I need to place the server in an array so I can iterate through them

I tried this
$ServerArray = ServerList.Text.Split("`n")

but the last value would not get picked up look like there is no new line there I tried to add a new line but no luck
any ideas
LVL 8
Leo TorresSQL DeveloperAsked:
Who is Participating?
 
RobSampsonCommented:
Hi, this has worked for me:
    $x=$objTextBox.Text
    $arr = $x -split "`r`n"
    foreach ($pc IN $arr) {
    	[System.Windows.Forms.MessageBox]::Show($pc)
    }

Open in new window


You may want to add a check for an empty $pc value in case there are blank lines.

Regards,

Rob.
0
 
Leo TorresSQL DeveloperAuthor Commented:
will test in the tomorrow. Thanks
0
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.

All Courses

From novice to tech pro — start learning today.