We help IT Professionals succeed at work.

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
Comment
Watch Question

Most Valuable Expert 2012
Top Expert 2014
Commented:
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.

Author

Commented:
will test in the tomorrow. Thanks