Windows Server TechCenter > Windows Server Forums > Windows PowerShell > powers shell creating multiple mailbox users with AD attributes

Answered powers shell creating multiple mailbox users with AD attributes

  • Monday, July 12, 2010 3:44 PM
     
     

    Hi guys,
    trying to create new mailbox users by importing from CSV file.
    the target is to create users with exchange attributes and AD attributes through the same script.
    after some searching i assemble this script and it's working:

    First i ran this line at the EX shell:

    $password=Read-Host "Enter Password" -AsSecureString
    then i enter password

    after creating the password, i ran this script:

    Import-CSV "C:\Users\Administrator\Desktop\CreateRecipients.csv" | foreach {new-mailbox -alias $_.alias -name $_.name -UserPrincipalName $_.UPN -database "Mailbox Database" -org "newusers" | set-user -phone $_.phone -FirstName $_.FirstName -LastName $_.LastName -Initials $_.Initials -SamAccountName $_.SamAccountName -DomainController $_.DomainController -DisplayName $_.DisplayName -Department $_.Department -Mobile $_.Mobile}

    the user was created succesfuly.

    the problam appears when i'm trying to include
    different attributes for AD and Exchange. for example, if i run the next code:

    Import-CSV "C:\Users\Administrator\Desktop\CreateRecipients.csv" | foreach {new-mailbox -alias $_.alias -name $_.name -UserPrincipalName $_.UPN -database "Mailbox Database" -org "newusers" | set-user -phone $_.phone -FirstName $_.FirstName -LastName $_.LastName -Initials $_.Initials -SamAccountName $_.SamAccountName -DomainController $_.DomainController -DisplayName $_.DisplayName -Department $_.Department -Mobile $_.Mobile -homePhone $_.homePhone -physicalDeliveryOfficeName $_.physicalDeliveryOfficeName}

    then i get the next error: "Set-User : A parameter cannot
    be found that matches parameter name 'physicalDeliveryOfficeName'.

    of course, I didn't forgat to update the CSV file with the correct fields and values.

    if i try some other attributes such as "Description" i also get this error.

    i used the exact LDAP name on the attributes, so i don't know where the problem is.
    can somone please give me a hint about this issue,
    how to create mailbox users with full AD attributes from powershell.

    the reason i choose this way is because ihave to create 200 users and doing it mnaually seems wrong.

    Thanks a lot!

Answers

  • Thursday, July 15, 2010 3:06 PM
     
     Answered

    Hi,

    I have put this page on creating bulk users, check the link http://www.myexchangeworld.com/?p=4

    thanks

    Thiyagu


    Thiyagu | MCTS/MCITP - Exchange 2007 | MCSE 2003[Messaging] | http://www.myExchangeWorld.com. This posting is provided "AS IS" with no warranties, and confers no rights.
  • Friday, July 16, 2010 8:36 AM
    Moderator
     
     Answered

    Hi,

    Generally, we can set user’s AD attributes using the script below:

    $user = =[ADSI]LDAP://CN=Ben Pearce,OU=London,DC=umpadom,DC=com
    $user.psbase.invokeset(‘Title’,’IT PRO’)
    $user.setinfo()

    Your script could be modified as below:

    $reps=Import-CSV "C:\Users\Administrator\Desktop\CreateRecipients.csv"
    Foreach($rep in $reps)
    {
    $user=new-mailbox -alias $rep.alias -name $rep.name -UserPrincipalName $rep.UPN -database "Mailbox Database" -org "newusers"
    $dn=$user.distinguishedName
    $user=[ADSI]"LDAP://$dn"

    $user.psbase.invokeset("physicalDeliveryOfficeName",$rep.physicalDeliveryOfficeName)
    $user.psbase.invokeset("homePhone",$rep.homePhone)

    #Add other invokeset() command if necessary
    ….
    $user.setinfo()
    }

    Thanks.


    This posting is provided "AS IS" with no warranties, and confers no rights. Please remember to click "Mark as Answer" on the post that helps you, and to click "Unmark as Answer" if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.

All Replies

  • Tuesday, July 13, 2010 2:52 PM
     
     

    Try the first New-Mailbox command, and then run eithe the Quest AD Cmdlets or a self made ADSI script.

    Set-User doesn't support the attributes you are trying to modify:
    http://technet.microsoft.com/en-us/library/aa998221(EXCHG.80).aspx

    Quest FREE cmdlets:
    http://www.quest.com/powershell/activeroles-server.aspx

    I can help with [ADSI] LDAP calls, if needed.

    Karl


    http://unlockpowershell.wordpress.com
    -join("6B61726C6D69747363686B65406D742E6E6574"-split"(?<=\G.{2})",19|%{[char][int]"0x$_"})
  • Tuesday, July 13, 2010 7:21 PM
     
     

    Hi Karl,

    thank's for taking the time to help me.

    i don't have much experience with scripting. built a VBS script once, for creating AD 2003 users and it took me 3 days of searching and asking.

    i'm not familier with ADSI or Quest, so i just wanna make sure i got you right.

    first, i understand that there is no way to create mailbox user with all AD attributes only separately?

    i mean first the mailbox user and then adding the rest of AD attributes?

    second i'm really short in time, so what option, in your opinion, will be the quickest one for a novice like me?

    Thanks again!

  • Tuesday, July 13, 2010 8:17 PM
     
     

    Within the same scriipt, you can call the New-Mailbox and then the QAD cmdlet.

    That's the way I'd go - add quest cmdlets to your workstation, and then after teh working New-Mailbox call, do a Set-QADUser with the required paramaters.

    See http://wiki.powergui.org/index.php/Set-QADUser

    Karl


    http://unlockpowershell.wordpress.com
    -join("6B61726C6D69747363686B65406D742E6E6574"-split"(?<=\G.{2})",19|%{[char][int]"0x$_"})
  • Thursday, July 15, 2010 3:06 PM
     
     Answered

    Hi,

    I have put this page on creating bulk users, check the link http://www.myexchangeworld.com/?p=4

    thanks

    Thiyagu


    Thiyagu | MCTS/MCITP - Exchange 2007 | MCSE 2003[Messaging] | http://www.myExchangeWorld.com. This posting is provided "AS IS" with no warranties, and confers no rights.
  • Friday, July 16, 2010 8:36 AM
    Moderator
     
     Answered

    Hi,

    Generally, we can set user’s AD attributes using the script below:

    $user = =[ADSI]LDAP://CN=Ben Pearce,OU=London,DC=umpadom,DC=com
    $user.psbase.invokeset(‘Title’,’IT PRO’)
    $user.setinfo()

    Your script could be modified as below:

    $reps=Import-CSV "C:\Users\Administrator\Desktop\CreateRecipients.csv"
    Foreach($rep in $reps)
    {
    $user=new-mailbox -alias $rep.alias -name $rep.name -UserPrincipalName $rep.UPN -database "Mailbox Database" -org "newusers"
    $dn=$user.distinguishedName
    $user=[ADSI]"LDAP://$dn"

    $user.psbase.invokeset("physicalDeliveryOfficeName",$rep.physicalDeliveryOfficeName)
    $user.psbase.invokeset("homePhone",$rep.homePhone)

    #Add other invokeset() command if necessary
    ….
    $user.setinfo()
    }

    Thanks.


    This posting is provided "AS IS" with no warranties, and confers no rights. Please remember to click "Mark as Answer" on the post that helps you, and to click "Unmark as Answer" if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
  • Saturday, July 17, 2010 6:49 AM
     
     

    Hi guys,

    thanks for the answers i finally got it to work. i went with Thiyagu14 advice.

    Tahnks again:)