Need Powershell command pull .csv assigning O365 perms

Jody Davis
Jody Davis used Ask the Experts™
on
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 :)
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2015
Distinguished Expert 2018

Commented:
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
Top Rated Freelancer on MS Technologies
Awarded 2018
Distinguished Expert 2018
Commented:
csv format:
PrimarySmtpAddress, UsertoReceiveFullAccess
main@domain.com,admin@domain.com


$outputfile="C:\path\output.csv"
$inputfile = "D:\inputs\inputs.csv"
$results=@()

Import-Csv  $inputfile | % { 
   $result= Add-MailboxPermission $_.PrimarySmtpAddress -User $_.UsertoReceiveFullAccess -AccessRights FullAccess
   $results+= New-Object psobject -property @{'result'=$result; PrimarySmtpAddress = $_.PrimarySmtpAddress; UsertoReceiveFullAccess= $_.UsertoReceiveFullAccess}
}
$results | Convertto-csv -notypeinformation $outputfile

Open in new window

Jody DavisSystems Engineer

Author

Commented:
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 DavisSystems Engineer

Author

Commented:
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
   RemotingTransportException
    + FullyQualifiedErrorId : JobFailure
    + PSComputerName        : ps.outlook.com
Jose Gabriel Ortega CastroTop Rated Freelancer on MS Technologies
Awarded 2018
Distinguished Expert 2018

Commented:
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.
main@domain.com,admin@domain.com

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 :)

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