Welcome Forums General PowerShell Q&A Problems with incorrect for loop to list a server and then run a command against

Viewing 1 reply thread
  • Author
    • #172850
      Topics: 6
      Replies: 3
      Points: 76
      Rank: Member

      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:





      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)
                   } Else {
    • #172900
      Topics: 2
      Replies: 1736
      Points: 3,551
      Helping Hand
      Rank: Community Hero

      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.


Viewing 1 reply thread
  • The topic ‘Problems with incorrect for loop to list a server and then run a command against’ is closed to new replies.