none
powershell - 'Description' field within AD RRS feed

  • Question

  • 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.

    Friday, April 24, 2015 5:00 PM

Answers

  • Just use Set-ADUser instead of Set-User and add the -Description parameter. The Set-ADUser cmdlet supports -Company and -Office.

    Richard Mueller - MVP Directory Services

    Friday, April 24, 2015 6:35 PM
    Moderator

All replies

  • 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
    Friday, April 24, 2015 5:23 PM
  • 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?
    Friday, April 24, 2015 5:32 PM
  • 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


    Don't retire TechNet! - (Don't give up yet - 13,225+ strong and growing)

    Friday, April 24, 2015 5:52 PM
  • Just use Set-ADUser instead of Set-User and add the -Description parameter. The Set-ADUser cmdlet supports -Company and -Office.

    Richard Mueller - MVP Directory Services

    Friday, April 24, 2015 6:35 PM
    Moderator
  • 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
    Friday, April 24, 2015 7:58 PM
  • 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 will.


    Richard Mueller - MVP Directory Services


    Friday, April 24, 2015 8:20 PM
    Moderator
  • 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.

    Friday, April 24, 2015 8:45 PM
  • 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.


    Richard Mueller - MVP Directory Services

    Friday, April 24, 2015 8:54 PM
    Moderator
  • 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.


    Richard Mueller - MVP Directory Services

    Friday, April 24, 2015 9:06 PM
    Moderator