Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Howto specify more than one mailbox to sync from command line ? #88

Open
buzzzo opened this issue Jul 27, 2023 · 5 comments
Open

Howto specify more than one mailbox to sync from command line ? #88

buzzzo opened this issue Jul 27, 2023 · 5 comments

Comments

@buzzzo
Copy link

buzzzo commented Jul 27, 2023

As per subject I can't figure out the exact syntax of -mailboxlist when using more than one entries.
Every time i'm trying to specify in some format the script gives error.

Thx

@grahamr975
Copy link
Owner

grahamr975 commented Aug 1, 2023

You can't define a PowerShell list in a batch file. The easiest way to do this is to edit the EWSContactSync.ps1 file. Change the Mandatory value of the MailboxList parameter from $True to $False. Then, write in your custom addresses in the following format: @(email1, email2, emai3, etc...). At this point, you should remove the MailboxList argument from your batch file since you already defined the emails in EWSContactSync.ps1. See below for an example of what EWSContactSync.ps1 should look like. Hopefully this helps.

[Parameter(Mandatory=$False)]
    [String[]]
    $MailboxList = @(john.doe1@mycompany.com, john.doe2@mycompany.com, , john.doe3@mycompany.com)

@buzzzo
Copy link
Author

buzzzo commented Aug 2, 2023

Thx for response.

I've ended up by modifying the ps1 file but just let get the email addresses list from an external file and then populate the array via foreach loop.

Thx for help

@BerryC
Copy link

BerryC commented Sep 8, 2023

Hi Buzzzo,

Do you have an example of the modified ps1 file?

@philipfredberg
Copy link

@buzzzo do you have an example of the file/foreach loop that you can share?

@buzzzo
Copy link
Author

buzzzo commented Nov 17, 2023

Hi

I've manage to create a txt file with all the mailbox name to sync and calling it in the EWSContactSync script to populate an array.

So:

  1. an external script create a file with ALL the username@domain i would like to sync.
    This is the script:
    (Group_To_Sync is the nome of the AD group holding ALL the user i would like to create the gal, so basically of user in this group will be written in mailboxsync.txt file)

$file = "c:\o365\gal-exo\mailboxtosync.txt"

if (Test-Path $file ) {
Remove-Item $file
}

$users = Get-ADGroupMember Group_To_Sync | %{get-aduser $_.SamAccountName | select userPrincipalName } | Select-Object -ExpandProperty userPrincipalName |Out-File -filepath $file

  1. I've add this on ewcontactsync script:

if ( Test-Path -Path "c:\o365\gal-exo\mailboxtosync.txt" -PathType Leaf ) {
$MailboxList = Get-Content -Path @("C:\o365\gal-exo\mailboxtosync.txt")
}

Of course you need to run script1 BEFORE ewcontactsync script in order to create the mailboxtosync.txt script

Hope this can help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants