ForEach Trouble – I’m sure I’m Missing Something Small

Welcome Forums General PowerShell Q&A ForEach Trouble – I’m sure I’m Missing Something Small

Viewing 4 reply threads
  • Author
    Posts
    • #238460
      Participant
      Topics: 9
      Replies: 11
      Points: 151
      Rank: Participant

      I know what I’m doing wrong, but I don’t know how to code myself out of the problem.

      I am trying to get all of the users for a specific Distribution Group, but I’m only using one variable.  Can someone help get me out of this paper bag I’ve put over my head?

      Thanks,

      -Rob

       

    • #238475
      Participant
      Topics: 0
      Replies: 37
      Points: 372
      Helping Hand
      Rank: Contributor

      Hello R_Martin,
      You are closing your nested foreach loop to soon. Simply move closing bracket “ }” from line #10 to line #20.

      Also I noticed that you are using += operator to dynamically add objects to $Rollup array. += Operator is not best approach as it is very time consuming. And during execution of your script your Office365 session might be dropped and script will fail. I would suggest to use ArrayList.
      Substitute line #2 to following

      and line #16 to

      Hope that helps.

    • #238598
      Participant
      Topics: 9
      Replies: 11
      Points: 151
      Rank: Participant

      Hello Andy!

      Thank you for your help.  It works perfectly now.  The only thing I added was on line 16 I did the following to keep it from counting up on screen.

      Thanks again!
    • #238631
      Participant
      Topics: 0
      Replies: 37
      Points: 372
      Helping Hand
      Rank: Contributor

      Glad that you figured it out.

      More PowerShellish way would be to pipe it to Out-Null

      =)

      Hope that helps.

    • #238697
      js
      Participant
      Topics: 32
      Replies: 842
      Points: 2,687
      Helping Hand
      Rank: Community Hero

      Where do those red spaces come from again (non-breaking spaces or nbsp?

      • This reply was modified 2 months, 3 weeks ago by js.
Viewing 4 reply threads
  • You must be logged in to reply to this topic.