I'm trying to create a powershell script for our first line support to help them with the account creation process in Office 365.
One step of the script is to get a list of shared mailboxes and ask the user to insert which shared mailboxes the new account should have access to.
I've copied a previous script for a similar task when adding a new account to certain groups, but I can't get this one to work.
I'm very new to powershell scripting so it might be a very small issue or maybe I should attack it from a whole different angle.
Here's the script:
#Prompt user for shared mailboxes Get-Mailbox -Filter '(RecipientTypeDetails -eq "SharedMailbox")' | Select Alias | Format-Table $sharedmailboxes = Read-Host "Copy the shared mailboxes the account should access. Separate multiple mailboxes with comma (,)" $sharedmailboxdata = $sharedmailboxes.Split(",").Trim(" ") #Adding new account to shared mailboxes Write-Host -BackgroundColor Black -ForegroundColor Yellow "Adding account to shared mailboxes" ForEach ($line in $sharedmailboxdata) { $sharedmailboxobject = Get-Mailbox -RecipientTypeDetails Shared | Select-Object $line Add-MailboxPermission -Identity $sharedmailboxobject -User $UserPrincipalName -AccessRights FullAccess -InheritanceType all }
With this script I get the following error:
Cannot process argument transformation on parameter 'Identity'. Cannot convert the "System.Collections.ArrayList" value of type "System.Collections.ArrayList" to type "Microsoft.Exchange.Configuration.Tasks.MailboxIdParameter".+ CategoryInfo : InvalidData: (:) [Add-MailboxPermission], ParameterBindin...mationException
+ FullyQualifiedErrorId : ParameterArgumentTransformationError,Add-MailboxPermission
+ PSComputerName : ps.outlook.com