Link to home
Avatar of Jody Davis
Jody DavisFlag 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 -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 :)
Avatar of Vasil Michev (MVP)
Vasil Michev (MVP)
Flag of Bulgaria image

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 -AccessRights FullAccess -Automapping $false }

Open in new window

where the file blabla.csv has a column PrimarySmtpAddress containing all the relevant mailbox addresses
Avatar of J0rtIT
Flag of Venezuela, Bolivarian Republic of image

Blurred text
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of 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.
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 -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
    + FullyQualifiedErrorId : JobFailure
    + PSComputerName        :
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 "" account into the "" 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 -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 :)