Problems with incorrect for loop to list a server and then run a command against

When I run the cmdlet Get-CMDistributionPointInfo | select ServerName to get a list of SCCM distribution points (DPs) by itself, I will get the following results example:

server1.corp.com

server2.corp.com

server3.corp.com

etc.

When I run the for loop below, I can do a write-host and it will list the DPs, but it does so several times for each DP result, so obviously the code is not correct. Also, if I do a write-host in that for loop, it will show the server name, but if I do a message box, it will not show one server after the next.

Ultimately, what I am trying to do is after it gets each DP server, to then create a directory on a specific drive on that server. That part I can handle, but I am having issues with the for loop just displaying the server in a message box and then the next one and then so on.

Any help would be greatly appreciated!

 

$GET_DP = Get-CMDistributionPointInfo | select ServerName

foreach($GET_DPS in $GET_DP)
{
     if($GET_DPS -ne $GET_DP)
     {
          Write-Output ($GET_DP)
[System.Windows.MessageBox]::Show($GET_DP)
             } Else {
     }
}

When you crosspost the same question at the same time to different forums you should provide this info to the people willing to help you. So they do not give you advices twice.

https://social.technet.microsoft.com/Forums/en-US/f0283023-cccd-45e2-a789-27e52f776f9f/for-loop-problem-with-server-list-acquired-from-get-command?forum=winserverpowershell