grahamr975 / EWS-Office365-Contact-Sync

Uses Exchange Web Services to synchronize a Global Address List in Office 365 to a user's mailbox
MIT License
94 stars 21 forks source link

Bad request when I try to deploy contacts to our users #75

Closed S-Mellado closed 1 year ago

S-Mellado commented 1 year ago

I make a list with an array and foreach, like this:

$UserMailboxes = Get-Mailbox -ResultSize Unlimited | Where {$_.RecipientTypeDetails -eq “UserMailbox”} $array = @() Foreach ($UserMailboxes in $UserMailboxes) { $Mailbox = $UserMailboxes.userprincipalname $Comillas = '"' $Mailbox1 = $Comillas + $Mailbox + $Comillas + ',' $array = $array + $Mailbox1 }

And when I execute the ps1 with the atribute -MailboxList $array I have an error in every mailbox

image

Can you help me? I don't know what's the problem. Thanks!

grahamr975 commented 1 year ago

@S-Mellado

The below line is causing your issue. $Mailbox1 = $Comillas + $Mailbox + $Comillas + ',' You don't need to add quotes and commas to each item when you append to an array. PowerShell can handle this by itself.

Furthermore, you don't need to loop through each user to extract the UserPrincipalName. Please try the below code instead to create your UserPrincipalName list. $array = $(Get-Mailbox -ResultSize unlimited | Where-Object {$_.RecipientTypeDetails -eq "UserMailbox"}).userprincipalname

grahamr975 commented 1 year ago

Closing to due lack of response...