Clean inside an OU contacts - PowerShell

Hello,

I need to import contacts every night of a business application.
They are either deleted, created or update contacts.

My import command works perfectly. All this goes to a specific OU Contacts in AD.

My question is whether there was a command to update all this or just to empty the OU.

thank you,

import-csv c:\test.csv -Delimiter ';' | foreach { new-mailcontact -alias $_.Alias -name $_.displayName -ExternalEmailAddress $_.eMailAddress -OrganizationalUnit domaine.fr/architecture/utilisateurs/Contacts}

July 29th, 2015 4:00am

you can use set-mailcontact for updating 

create a filter to get list of mailcontact, validate with the csv file (if contact exists) set-mailcontact else (new-mailcontact)

  • Proposed as answer by Vishwanath.S 23 hours 18 minutes ago
Free Windows Admin Tool Kit Click here and download it now
July 29th, 2015 4:14am

Thx a lot but i don't have the level for do that.

Is it possible to empty the OU ?

I will reimport after the list.



  • Edited by Bartoch 22 hours 56 minutes ago
July 29th, 2015 4:36am

Yes you can empty the OU and import the contact list again
Free Windows Admin Tool Kit Click here and download it now
July 29th, 2015 5:19am

yes but which command Shell can empty an OU ?

I have find delete OU but i don't find just for empty the OU.

July 29th, 2015 5:37am

get-mailcontact  -OrganizationalUnit domaine.fr/architecture/utilisateurs/Contacts" -resultsize unlimited | remove-mailcontact -confirm:$false

This will get all the mailcontacts in the OU and delete it

  • Proposed as answer by Vishwanath.S 21 hours 37 minutes ago
  • Marked as answer by Bartoch 18 hours 32 minutes ago
Free Windows Admin Tool Kit Click here and download it now
July 29th, 2015 5:55am

Thx a lot !
July 29th, 2015 9:00am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics