Hi Guys,

I have written the script bellow and it given me an error also shown bellow. Is anyone able to tell me why this keeps happening?

Script

#Get the Canonical Name for each user in the group DG_Mailenabled_SecurityGroup
$consultants = Get-ADGroupMember -Identity DG_Mailenabled_SecurityGroup

#create an array called logins where each entry in that array is the AD Account for the user
$logins = foreach($aduser in $consultants){
                                Get-ADUser -Identity $aduser -Properties mail | select-object mail
                                          }

#Get the mailbox identity for each of the AD accounts found
$mailboxes = foreach($login in $logins){
                    get-mailbox -identity $logins
                                       }

#grant the group DG_Mailenabled_SecurityGroup access to all of the mailboxes
foreach($mailbox in $mailboxes){
                    Add-MailboxFolderPermission -Identity $mailbox `
                                                -User DG_Mailenabled_SecurityGroup `
                                                -AccessRights Reviewer
                               }
                        

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: (:) [Get-Mailbox], ParameterBindin...mationException
    + FullyQualifiedErrorId : ParameterArgumentTransformationError,Get-Mailbox
    + PSComputerName        : cob-excm03.cobalt.local
1 Spice up

The Get-Mailbox line needs to reference $login, not $logins.

$mailboxes = foreach($login in $logins){
    Get-Mailbox -Identity $login.mail
    }
2 Spice ups

this can be cut short

foreach ($login in (Get-ADGroupMember -Identity "DG_Mailenabled_SecurityGroup" |Get-ADUser -Properties mail |Select-Object mail))
{
$mailbox=$login.mail
                    Add-MailboxFolderPermission -Identity $mailbox `
                                                -User DG_Mailenabled_SecurityGroup `
                                                -AccessRights Reviewer
                               }