We help IT Professionals succeed at work.

Need Powershell command pull .csv assigning O365 perms

Jody Davis
Jody Davis asked
on
121 Views
1 Endorsement
Last Modified: 2019-01-03
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

CERTIFIED EXPERT
Most Valuable Expert 2015
Distinguished Expert 2019

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
CEO Faru Bonon IT&Agency /Top-Rated Freelancer (Upwork)/Photographer
CERTIFIED EXPERT
Awarded 2018
Distinguished Expert 2018
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
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 CastroCEO Faru Bonon IT&Agency /Top-Rated Freelancer (Upwork)/Photographer
CERTIFIED EXPERT
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 :)

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.