[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2077
  • Last Modified:

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?
0
ThinkPaper
Asked:
ThinkPaper
1 Solution
 
SieQCommented:
Becuase it's more AD property you should use
set-contact $line.displayName -department "DeptName"

same as get/set-mailbox and get/set-user, some attributes can be set with set-mailbox and some with set-user
0
 
ThinkPaperAuthor Commented:
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"

}
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now