Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

How do I add multiple users to a Powershell command so that they have access to a calendar on a mailbox?

Posted on 2014-07-24
8
Medium Priority
?
2,784 Views
Last Modified: 2014-09-01
I have the command I need to add one user to my calendar -
Add-MailboxFolderPermission John:\calendar  -AccessRight PublishingEditor -User Suzan 

Open in new window


But what if, in addition to Suzan, I want Patrick, Adrian and Paul?

thanks
0
Comment
Question by:fuzzyfreak
  • 5
  • 3
8 Comments
 
LVL 14

Expert Comment

by:Justin Yeung
ID: 40217093
[array]$Users = @("Suzan","Patrick","Adrian","Paul")
foreach ($User in $Users)
{
Add-MailboxFolderPermission John:\calendar  -AccessRight PublishingEditor -User $User
}
0
 
LVL 4

Author Comment

by:fuzzyfreak
ID: 40217341
Justin, can you please put the code tags around this because the spaces are confusing me - I tried the code without the spaces and it doesn't like various parts such as 'foreach' and 'in' and '(' and ')'

thanks
0
 
LVL 14

Expert Comment

by:Justin Yeung
ID: 40217395
[array]$Users = @("Suzan","Patrick","Adrian","Paul")
 foreach ($User in $Users)
 {
 Add-MailboxFolderPermission John:\calendar  -AccessRight PublishingEditor -User $User
 } 

Open in new window

0
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 
LVL 4

Author Comment

by:fuzzyfreak
ID: 40254489
Thanks I'll give this a go once back in the office.
0
 
LVL 4

Author Comment

by:fuzzyfreak
ID: 40290530
Justin, thank you very much, this worked perfectly!

I now wish to apply this to multiple mailboxes, I tried adjusting that script to simply add the additional one underneath but this did not work, see below for example -

[array]$Users = @("Suzan","Patrick","Adrian","Paul")
 foreach ($User in $Users)
 { Add-MailboxFolderPermission John:\calendar  -AccessRight PublishingEditor -User $User }
 { Add-MailboxFolderPermission alan:\calendar  -AccessRight PublishingEditor -User $User } 

Open in new window

0
 
LVL 14

Accepted Solution

by:
Justin Yeung earned 2000 total points
ID: 40295071
foreach command needs to run within the script block {}

example
 
[array]$abc = @("1","2","3")
foreach ($abc in $abc}
{
write-host "1"
write-host "2"
}

write-host 3

the result will be

1
2
1
2
1
2
3

since we have 3 object in the array, so command 1 (write-host "1") and command 2 (write-host "2") will run 3 times
and command 3 will execute after the foreach command completed, so write-host "3" with result 3 will appear at this end.

so in your scenario, the command should be like below.

[array]$Users = @("Suzan","Patrick","Adrian","Paul")
 foreach ($User in $Users)
 {
 Add-MailboxFolderPermission John:\calendar  -AccessRight PublishingEditor -User $User 
 Add-MailboxFolderPermission alan:\calendar  -AccessRight PublishingEditor -User $User 
} 

Open in new window

0
 
LVL 4

Author Comment

by:fuzzyfreak
ID: 40296998
This is perfect, worked like a dream.

thank you very much!
0
 
LVL 4

Author Closing Comment

by:fuzzyfreak
ID: 40296999
Excellent solution!
0

Featured Post

Simplify Active Directory Administration

Administration of Active Directory does not have to be hard.  Too often what should be a simple task is made more difficult than it needs to be.The solution?  Hyena from SystemTools Software.  With ease-of-use as well as powerful importing and bulk updating capabilities.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have come across a situation where you need to find some EDB mailbox recovery techniques, then here you will find the same. In this article, we will take you through three techniques using which you will be able to perform EDB recovery. You …
Upgrading from older Exchange server to the latest Exchange server can be tiresome, error-prone and risky, without being a seasoned exchange server administrators. It can become even problematic if you're an organization that runs on tight timeline…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question