Looping through a script with two variables

Welcome Forums General PowerShell Q&A Looping through a script with two variables

Viewing 4 reply threads
  • Author
    Posts
    • #264506
      Participant
      Topics: 1
      Replies: 2
      Points: 17
      Rank: Member

      I need to block all student access to all faculty Outlook calendars. I can use the below script but I need to pass two variables, a list of 800 faculty and a list of 40,000 students. How do I make sure the script loops through every user for every mailbox?

      add-mailboxfolderpermission -identity “$faculty`:\calendar” -user $students -accessrights none

    • #264545
      Senior Moderator
      Topics: 9
      Replies: 1422
      Points: 5,289
      Helping Hand
      Rank: Community MVP

      You can use common looping statements. The most commonly used one in PowerShell is the Foreach keyword. Below documentation will help you to do it.

      https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_foreach?view=powershell-7

    • #264632
      Participant
      Topics: 1
      Replies: 2
      Points: 17
      Rank: Member

      Yeah, i am having trouble figuring out how to loop through the two variables.  Thanks for the link; i am still confused about this.

    • #264644
      Participant
      Topics: 2
      Replies: 382
      Points: 523
      Helping Hand
      Rank: Major Contributor

      One way of doing it is to nest the foreach loops:

      I wonder if you do need to loop through all the students though.  Surely, the best way to do this is to have all students in a group, and add the group to all mailboxes.  You really don’t want 40,000 objects in each mailbox ACL.

    • #264647
      Participant
      Topics: 1
      Replies: 2
      Points: 17
      Rank: Member

      Oh, what a great idea! Of course, I didn’t even think of using a group. Thank you so much for the example also! Makes perfect sense when I see it now.

Viewing 4 reply threads
  • You must be logged in to reply to this topic.