0
Trying to come up with a way to add users with send as right to a mailbox and also add them with full control rights to a security group. At the moment I'm doing it with the below command...
$User = "UserEmail"
$Mailbox = "MailboxEmail"
$MailboxAccess = "SecurityGroup"
Add-RecipientPermission -Identity $Mailbox -AccessRights SendAs -Trustee $User -Confirm:$false
Add-DistributionGroupMember -Identity $MailboxAccess -Member $User -Confirm:$false -BypassSecurityGroupManagerCheck
But know this isn't the fastest way because I have to manually find the mailbox emails from O365 Admin Portal. Was trying something like the below...
$User = "UserEmail"
$Mailbox = Get-Mailbox -RecipientTypeDetails SharedMailbox -Anr *MailboxName* | Select-Object PrimarySmtpAddress
$MailboxAccess = Get-Group -Anr *SecurityGroupName* | Select-Object WindowsEmailAddress
Add-RecipientPermission -Identity $Mailbox -AccessRights SendAs -Trustee $User -Confirm:$True
Add-DistributionGroupMember -Identity $MailboxAccess -Member $User -Confirm:$True -BypassSecurityGroupManagerCheck
But that's failing because the cmdlets don't support piping. Pretty new to Powershell so any help/advice would be much appreciated.
Edit
Error message received when running is...
PS C:\WINDOWS\System32\WindowsPowerShell\v1.0> Add-RecipientPermission -Identity
$Mailbox -AccessRights SendAs -Trustee $User -Confirm:$True
Cannot process argument transformation on parameter 'Identity'. Cannot convert
value "@{PrimarySmtpAddress=*EmailAddress*}" to type
"Microsoft.Exchange.Configuration.Tasks.RecipientIdParameter". Error: "Cannot
convert hashtable to an object of the following type:
Microsoft.Exchange.Configuration.Tasks.RecipientIdParameter.
Hashtable-to-Object conversion is not supported in restricted language mode or
a Data section."
+ CategoryInfo : InvalidData: (:) [Add-RecipientPermission], Para
meterBindin...mationException
+ FullyQualifiedErrorId : ParameterArgumentTransformationError,Add-Recipie
ntPermission
+ PSComputerName : outlook.office365.com
Also tried running it without the additional Select-Objects at the end and still get similar...
PS C:\WINDOWS\System32\WindowsPowerShell\v1.0> Add-RecipientPermission -Identity
$Mailbox -AccessRights SendAs -Trustee $User -Confirm:$True
Cannot process argument transformation on parameter 'Identity'. Cannot convert
value "*EmailDisplayName*" to type
"Microsoft.Exchange.Configuration.Tasks.RecipientIdParameter". Error: "Cannot
convert hashtable to an object of the following type:
Microsoft.Exchange.Configuration.Tasks.RecipientIdParameter.
Hashtable-to-Object conversion is not supported in restricted language mode or
a Data section."
+ CategoryInfo : InvalidData: (:) [Add-RecipientPermission], Para
meterBindin...mationException
+ FullyQualifiedErrorId : ParameterArgumentTransformationError,Add-Recipie
ntPermission
+ PSComputerName : outlook.office365.com
1Where does the second script fail? Could you please [edit] your question to include the error message you get? Thanks! – Ben N – 2017-03-23T16:55:40.040
Yeah no problem, that's been added. – Jim Thomas – 2017-03-24T09:35:03.507