Exchange Powershell - Importing CSV question

garryshape
garryshape used Ask the Experts™
on
I have this code here that will let me specify mailboxes in one column and the users who can be granted access to that mailbox in the other column:

$Thelist = Import-csv “H:\MailboxAccess.csv”
ForEach($theobject in $thelist) {$theMBDN = (Get-Mailbox $theobject.themailbox).distinguishedname;
Add-ADPermission $thembDN -Extendedrights “Send As” -User $theobject.theuser;
Add-MailboxPermission $thembDN -Accessrights “FullAccess” -User $theobject.theuser 

Open in new window



But lets say I want 6 different users to have access to each other's mailboxes.
Instead of repeating each user's mailbox 6 times in the TheMailbox column, can I just put each person's mailboxname once in both columns, and have a script that loops through each one until each person has accesss to eachother's mailbox?

I attached the current CSV I'm working with so show you the redundancy I'm trying to eliminate.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Hello there, I don't see any attached files, and your variable names confuse me a little, but you essentially want to loop through your list twice, once with an outer loop, then once with an inner loop.

Something like this should work:
$Thelist = Import-csv "H:\MailboxAccess.csv"
ForEach ($theobject in $thelist)
{
	foreach ($theobject2 in $thelist)
	{
		$theMBDN = (Get-Mailbox $theobject2.themailbox).distinguishedname
		Add-ADPermission $thembDN -Extendedrights “Send As” -User $theobject.theuser
		Add-MailboxPermission $thembDN -Accessrights “FullAccess” -User $theobject.theuser
	}
}

Open in new window

You may create a Security group and assign the permission.

$thelist=Import-csv “H:\MailboxAccess.csv”
ForEach($theobject in $thelist) {$theMBDN = (Get-Mailbox $theobject.themailbox).distinguishedname;
Add-ADPermission $thembDN -Extendedrights “Send As” -User $theobject.thegroup;
Add-MailboxPermission $thembDN -Accessrights “FullAccess” -User $theobject.thegroup 

Open in new window


Modify your CSV file like attachment.

Once run the above Powershell, you may manually or use powershell script o add the users to the Security group.
MailboxAccess.csv

Author

Commented:
Ty for solutions. Security Group wont work in this case but I'm sure it will help me when the time comes in the future.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial