Reputation: 81
Having issues with remove-mailboxPermission and Add-MailboxPermission. I receive the following error:
The Command Get-Mailbox works however the rest does not (note: I've edited out our DNS)
#PowerShell script to add access to an email and not map
Set-ExecutionPolicy RemoteSigned
$UserCredential = Get-Credential
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection
Import-PSSession $Session -DisableNameChecking
Get-Mailbox [email protected]
Remove-MailboxPermission -Identity [email protected] -User [email protected] -AccessRights FullAccess
Add-MailboxPermission -Identity [email protected] -User [email protected] -AccessRights FullAccess -AutoMapping:$false
Remove-PSSession $Session
Upvotes: 1
Views: 1638
Reputation: 137
The error "A term _____ is not recognized as the name of a cmdlet..." can be misleading. If your syntax is correct it usually means that you don't have sufficient permission to run that commandlet.
You can use this guide to find out which specific permission you need to run each cmdlet: https://learn.microsoft.com/en-us/powershell/exchange/exchange-server/find-exchange-cmdlet-permissions?view=exchange-ps
You may be wondering "why doesn't it just tell me that I don't have permission?" It makes a little more sense when you understand why you get this error. Remember that your session can't see(for lack of a better term) parameters or commandlets you don't have permissions for. So depending on what you are trying to do PowerShell may tell you "thats not a valid command" or "thats not a valid parameter", when in fact those are valid commmands and parameters, your session just can't see them if you don't have access to run it. This will also happen if you are connected to a wrong URI in your O365 PowerShell session(e.g. the compliance uri instead of the outlook uri)
EDIT: This site says you need to be a member of the "Organization Management" group in order to run these cmdlets.
Upvotes: 1