Avatar of Jody Davis
Jody Davis
Flag for United States of America asked on

Need Powershell command pull .csv assigning O365 perms

I need a Powershell command to assign O365 permissions to users pulling from a .csv and export result to a .csv. I'm currently using the following command :

Get-Mailbox -ResultSize unlimited | Add-MailboxPermission -User account@domainname.com -AccessRights FullAccess -InheritanceType all

- this is producing an error (used to work) i don't want to discuss/waste time talking to MS about. Everything i've seen online tells me to call MS - don't wanna call MS.

- if i can pull a list from .csv (please explain formatting) and export result to .csv i can pickup where the error leaves off and eventually finish perms. this is time-sensitive and don't want to do back and forth tryin resolutions. hope you understand.

Please lemme know :)
PowershellMicrosoft 365

Avatar of undefined
Last Comment
Jose Gabriel Ortega Castro

8/22/2022 - Mon
Vasil Michev (MVP)

Might help if you specify what error you are running into. In general, you can use something like this:

Import-CSV blabla.csv | % { Add-MailboxPermission $.PrimarySmtpAddress -User account@domainname.com -AccessRights FullAccess -Automapping $false }

Open in new window

where the file blabla.csv has a column PrimarySmtpAddress containing all the relevant mailbox addresses
Jose Gabriel Ortega Castro

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Jody Davis

Jose - please explain the csv formatting a little more - i'm not clear as to what's needed. sorry. and thanks ahead of time.
Jody Davis

Vasil - here is the error i'm receiving. The command below used to work all the way through our users. now it stops somewhere between the letter "B" and "D" every time.

Get-Mailbox -ResultSize unlimited | Add-MailboxPermission -User account@domainname.com -AccessRights FullAccess -InheritanceType all

Processing data for a remote command failed with the following error message:
The request for the Windows Remote Shell with ShellId
1A94C38B-0F7B-4313-A89F-238D018AD2DC failed because the shell was not found on
the server. Possible causes are: the specified ShellId is incorrect or the
shell no longer exists on the server. Provide the correct ShellId or create a
new shell and retry the operation. For more information, see the
about_Remote_Troubleshooting Help topic.
    + CategoryInfo          : OperationStopped: (ps.outlook.com:String) [], PS
    + FullyQualifiedErrorId : JobFailure
    + PSComputerName        : ps.outlook.com
Your help has saved me hundreds of hours of internet surfing.
Jose Gabriel Ortega Castro

A CSV it's a Comma Separated Values
So the 1st row of the Text file would be the "Name FIELDS"
I have selected 2 fields: PrimarySmtpAddress, UsertoReceiveFullAccess (these names are arbitrary).
And are the ones I use on the Powershell script  on line 6

1$result= Add-MailboxPermission $_.PrimarySmtpAddress -User $_.UsertoReceiveFullAccess -AccessRights FullAccess

From row 2, 1 user for each line.

Means that you are going to give full permissions to the "admin@domain.com" account into the "main@domain.com" mailbox.

if you run this, it would take the systems mailboxes so I'd modify it like this, to filter all the admin accounts, (you can also use the "b*"  or "c*"
get-mailbox -ResultSize unlimited | where{ $_.alias -notlike "admin*"} | %{
Write-host "Working with $_.alias"
Add-MailboxPermission $_.PrimarySmtpAddress[/b]  -User account@domainname.com -AccessRights FullAccess -InheritanceType all

I modified the pipe for a foreach because you do need to know which one is the one giving you issues and added the notlike so you can filter :)