Looping through a script with two variables

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

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.

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

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

$faculties = 'Maths','Music','Law','Art'
$students = 'Buffy','Willow','Xander','Cordelia'

foreach ($faculty in $faculties) {

    foreach ($student in $students) {

        Write-Output "$faculty - $student"
    
    }

}

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.

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.