powershell - 'Description' field within AD

Hello,

I am using powershell in Exchange 2010 and I am able to create multiple email address with the below code.  However, the only thing I'm not able to do is populate the 'Description' field within Active Directory.  Does someone know how I can do this?

$password = (Get-Credential).Password

Import-Csv c:\TLusers.csv | ForEach-Object {
    New-Mailbox -Name $_.Name `
    -FirstName $_.FirstName `
    -LastName $_.LastName `
    -UserPrincipalName $_.UserPrincipalName `
    -Password $password `
    -OrganizationalUnit $_.OU `
    -Database "RS_EXDB1" `
    | Set-User -Company $_.Company -Office $_.Office}

Thank you.

April 24th, 2015 1:01pm

There is no -Description parameter available when using the Exchange Set-User cmdlet, nor is there an -OtherAttributes parameter that accepts a hash table (as seen with some cmdlets). If you want to update the Description field, you're going to need to use the Active Directory cmdlet, Set-ADUser, or use an LDAP command.
Free Windows Admin Tool Kit Click here and download it now
April 24th, 2015 1:24pm

I have tried using Set-ADUser within the code but unfortunately I am not a programmer and I was unsuccessful.  Can you add in a line of code that will work with my code?
April 24th, 2015 1:33pm

I have tried using Set-ADUser within the code but unfortunately I am not a programmer and I was unsuccessful.  Can you add in a line of code that will work with my code?

You'll need to post exactly what you're using and your error messages. Here's the syntax:

http://ss64.com/ps/set-aduser.html

Free Windows Admin Tool Kit Click here and download it now
April 24th, 2015 1:53pm

Just use Set-ADUser instead of Set-User and add the -Description parameter. The Set-ADUser cmdlet supports -Company and -Office.
April 24th, 2015 2:37pm

So I put in the following and I get this error message:

Import-Module activedirectory
$password = (Get-Credential).Password

Import-Csv c:\TLusers.csv | ForEach-Object {
    New-Mailbox -Name $_.Name `
    -FirstName $_.FirstName `
    -LastName $_.LastName `
    -UserPrincipalName $_.UserPrincipalName `
    -Password $password `
    -OrganizationalUnit $_.OU `
    -Database "RS_EXDB1" `
    | Set-ADUser -Company $_.Company -Office $_.Office -Description $_.Description}

Update:  Sorry so small, the error message is the following:

Set-ADUser : The input object cannot be bound to any parameters for the command either because the command does not take pipeline input or the input and its properties do not match any of the parameters that take pipeline input.

  • Edited by nrgymover 10 hours 43 minutes ago
Free Windows Admin Tool Kit Click here and download it now
April 24th, 2015 3:59pm

Perhaps Set-User can accept the new object created by New-Mailbox in the pipeline, but Set-ADUser cannot. Is a new user object created? I note that none of the fields in the CSV file uniquely specifies the user object. The Name property, for example, must only be unique in the OU. What is the sAMAccountName of the new user? If it is the same as the Name, you can use the -Identity parameter if the Set-ADUser cmdlet and specify the Name field (which in that case must be unique in the domain).

Edit: The help for New-Mailbox states that the new user object created by this cmdlet assigns a value to sAMAccountName based on the userPrincipalName. Presumably the string before the "@" character is assigned to sAMAccountName. But userPrincipalName is not even required to have a value in Active Directory (much less be unique). It cannot be used to identify the object. You may be stuck unless you code to parse the userPrincipalName for the sAMAccountName. It would be easier to add a field to your CSV for sAMAccountName and specify this with the -Identity parameter of Set-ADUser. O f course, this assumes you can pipe New-Mailbox to Set-ADUser, and there is no timing issue where the object is not yet created. I cannot assume that because Set-User works this way that Set-ADUser

April 24th, 2015 4:21pm

Yes all the objects are created.  The samaccountname is correct.  It is using the UserPrincipalName column.  In that column is jsmith@abc.com.  so the samaccountname is jsmith.

Free Windows Admin Tool Kit Click here and download it now
April 24th, 2015 4:46pm

Can you add a field to the CSV for sAMAccountName? If so, you can specify it with the -Identity parameter of Set-ADUser.

I would still like to find an example where New-Mailbox is piped to Set-ADUser, to verify there is no timing issue. The Exchange people may have coded Set-User with this in mind, but the AD people may not.

April 24th, 2015 4:56pm

I found a forum thread indicating that there will be a timing issue:

https://social.technet.microsoft.com/Forums/exchange/en-US/10d3b8a3-b2dd-43b7-9a76-dd3659c79764/combine-newmailbox-with-other-cmdlets?forum=exchange2010

As noted, you may need to add a pause between New-Mailbox and Set-ADUser. You may need to use ForEach instead of piping, then add a Start-Sleep between the two cmdlets.

Free Windows Admin Tool Kit Click here and download it now
April 24th, 2015 5:08pm

There is no -Description parameter available when using the Exchange Set-User cmdlet, nor is there an -OtherAttributes parameter that accepts a hash table (as seen with some cmdlets). If you want to update the Description field, you're going to need to use the Active Directory cmdlet, Set-ADUser, or use an LDAP command.
  • Proposed as answer by Mike Laughlin Friday, April 24, 2015 6:37 PM
April 24th, 2015 5:23pm

So I put in the following and I get this error message:

Import-Module activedirectory
$password = (Get-Credential).Password

Import-Csv c:\TLusers.csv | ForEach-Object {
    New-Mailbox -Name $_.Name `
    -FirstName $_.FirstName `
    -LastName $_.LastName `
    -UserPrincipalName $_.UserPrincipalName `
    -Password $password `
    -OrganizationalUnit $_.OU `
    -Database "RS_EXDB1" `
    | Set-ADUser -Company $_.Company -Office $_.Office -Description $_.Description}

Update:  Sorry so small, the error message is the following:

Set-ADUser : The input object cannot be bound to any parameters for the command either because the command does not take pipeline input or the input and its properties do not match any of the parameters that take pipeline input.

  • Edited by nrgymover Friday, April 24, 2015 8:25 PM
Free Windows Admin Tool Kit Click here and download it now
April 24th, 2015 7:58pm

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

Other recent topics Other recent topics