Powershell – How to add a to the description field in ADUC using Powershell/Exchange Management Shell

active-directoryexchange-2007powershell

This is my first attempt at Powershell so bear with me if I have overlooked something simple. I've spent several days digging around online and have yet to come up with a good answer as to how to go about adding data to the Description field under the General tab in ADUC. I seem to be able to get everything else added just fine. I've referenced the Attribute Editor and it shows it as being called "description" but obviously that's not the case (or so it seems). I also noticed "Notes" was called "Info" in there, so I guess I can't use the Attribute Editor as a definitive source.

Anyway, I've found a few good references online to help me with this script, basically just wanting to be able to add a new user in AD via Exchange Management Shell, so some of this may look familiar to those that frequent Powershell forums.

#Define Environment Variables
$exchangeserver="EXCH07" 
$userou="OU=Users,DC=Company,DC=Com"
$companyname="XYZ"
$mailboxdatabase="Mailbox Database"

#Prompt for Username and Password
$firstname = read-host -prompt "Enter First Name"
$lastname = read-host -prompt "Enter Last Name"
$username = read-host -prompt "Enter User Name"
$department = read-host -prompt "Enter Department"
$title = read-host -prompt "Enter Job Title"
$manager = read-host -prompt "Enter Manager Username"
$phone = read-host -prompt "Enter Telephone Number"
$Name=$Lastname+", "+$Firstname
$accountpassword = read-host -assecurestring -prompt "Enter Password"
$upn = $username+ "@Company.com"
$description = read-host -prompt "Enter Description"
$office = read-host -prompt "Enter Office Location"
$notes = read-host -prompt "Enter the Organizational Chart Number"

#Create user and enable mailbox
New-Mailbox  -name $name -userprincipalname $upn -Alias $username -OrganizationalUnit $userou -SamAccountName $username -FirstName $FirstName -Initials '' -LastName $LastName -Password $accountpassword -ResetPasswordOnNextLogon $false -Database $mailboxdatabase

#Pause for 20 seconds for AD 
write-host -foregroundcolor Green "Pausing for 20 seconds for AD Changes"
Start-Sleep -s 20 

#Set user properties
Get-Mailbox $username | Set-User -Company $companyname -Department $department -title $title -Manager $manager -phone $phone -office $office -notes $notes -description $description

exit

When I rem out the -description line, it works fine, if I leave it in there it gives me an error "Set-User : A parameter cannot be found that matches parameter name 'description
'." I've seen references to using ADSI instead but It would be nice if this would work as every other field I've populated works just fine. Anyone have any suggestions as to what it might be called, or a valid reason why it simply won't work? I'm also posting a question with regards to giving rights to a folder via PS, but putting that in a separate question.

Best Answer

You are getting the error because you cannot set the description field using Set-User. This is an exchange CMDLET which does not allow for modification of that attribute. To modify the description attribute, you will need to use Set-ADUser. This is available in the Active Directory module. You can Import the Active Directory module using Import-module activedirectory. Something like this should help:

Import-Module ActiveDirectory
Set-ADUser -Company $companyname -Department $department -title $title -Manager $manager -officephone $phone -office $office -description $description

You will still need to set the "notes" attribute using Set-User.