Link to home
Start Free TrialLog in
Avatar of ThinkPaper
ThinkPaperFlag for United States of America

asked on

Set "Department" field for over 200 Contacts using Powershell

Experts-

I am currently running a powershell command to import a bulk list of contacts:

=============

$CSV=Import-Csv "C:\contacts\powershellContacts.csv"
foreach ($line in $CSV)
{
New-MailContact -Name $line.displayName -DisplayName $line.displayName -ExternalEmailAddress $line.emailAddress -LastName $line.sn -FirstName $line.givenName -Alias $line.alias1 -OrganizationalUnit "Finance"
}

=============

However, it does not set all the proper fields.

Is there a way to modify the "Department" field for all these contacts? I tried adding "-Department" but it did not work as it is not a valid argument. I also tried selecting the contacts in Active Directory to see if I could modify it through there, but there were no options to do this. I have over 200 contacts. Is there an easy way to do this?
ASKER CERTIFIED SOLUTION
Avatar of SieQ
SieQ
Flag of Poland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ThinkPaper

ASKER

THANKS! You are a life saver! I kept looking at New-MailContact and Set-MailContact, and did not even think to look to see if there was a "Set-Contact". That worked perfectly. Thanks!!

$CSV=Import-Csv "C:\contacts\Contacts.csv"
foreach ($line in $CSV)
{
$myPath = "blah.com/Contacts/Finance/" + $line.displayName

Set-Contact -Identity $myPath -Department "Finance"

}