JSI Tip 7371. How do I add a contact to Active Directory using the command-line?

Using the DSADD CONTACT command, you can add a contact from the command-line.

When you type dsadd contact /?, the parameters are displayed:

Description:  Adds a contact to the directory.
Syntax:  dsadd contact <ContactDN> \[-fn <FirstName>\] \[-mi <Initial>\]
        \[-ln <LastName>\] \[-display <DisplayName>\] \[-desc <Description>\]
        \[-office <Office>\] \[-tel <Phone#>\] \[-email <Email>\]
        \[-hometel <HomePhone#>\] \[-pager <Pager#>\] \[-mobile <CellPhone#>\]
        \[-fax <Fax#>\] \[-iptel <IPPhone#>\] \[-title <Title>\]
        \[-dept <Department>\] \[-company <Company>\]
        \[\{-s <Server> | -d <Domain>\}\] \[-u <UserName>\]
        \[-p \{<Password> | *\}\] \[-q\] \[\{-uc | -uco | -uci\}\]

Value                   Description
<ContactDN>             Required. Distinguished name (DN) of contact to add.
                        If the target object is omitted, it will be taken
                        from standard input (stdin).
-fn <FirstName>         Sets contact first name to <FirstName>.
-mi <Initial>           Sets contact middle initial to <Initial>.
-ln <LastName>          Sets contact last name to <LastName>.
-display <DisplayName>  Sets contact display name to <DisplayName>.
-desc <Description>     Sets contact description to <Description>.
-office <Office>        Sets contact office location to <Office>.
-tel <Phone#>           Sets contact telephone# to <Phone#>.
-email <Email>          Sets contact e-mail address to <Email>.
-hometel <HomePhone#>   Sets contact home phone# to <HomePhone#>.
-pager <Pager#>         Sets contact pager# to <Pager#>.
-mobile <CellPhone#>    Sets contact mobile# to <CellPhone#>.
-fax <Fax#>             Sets contact fax# to <Fax#>.
-iptel <IPPhone#>       Sets contact IP phone# to <IPPhone#>.
-title <Title>          Sets contact title to <Title>.
-dept <Department>      Sets contact department to <Department>.
-company <Company>      Sets contact company info to <Company>.
\{-s <Server> | -d <Domain>\}
                        -s <Server> connects to the domain controller (DC)
                        with name <Server>.
                        -d <Domain> connects to a DC in domain <Domain>.
                        Default: a DC in the logon domain.
-u <UserName>           Connect as <UserName>. Default: the logged in user.
                        User name can be: user name, domain\user name,
                        or user principal name (UPN).
-p \{<Password> | *\}
                        Password for the user <UserName>. If * is entered
                        then you are prompted for a password.
-q                      Quiet mode: suppress all output to standard output.
\{-uc | -uco | -uci\}     -uc Specifies that input from or output to pipe is
                        formatted in Unicode.
                        -uco Specifies that output to pipe or file is
                        formatted in Unicode.
                        -uci Specifies that input from pipe or file is
                        formatted in Unicode.

If you do not supply a target object at the command prompt, the target
object is obtained from standard input (stdin). Stdin data can be
accepted from the keyboard, a redirected file, or as piped output from
another command. To mark the end of stdin data from the keyboard or
in a redirected file, use Control+Z, for End of File (EOF).

If a value that you supply contains spaces, use quotation marks
around the text (for example, "CN=John Smith,CN=Users,DC=microsoft,DC=com").
See also:
dsadd computer /? - help for adding a computer to the directory.
dsadd contact /? - help for adding a contact to the directory.
dsadd group /? - help for adding a group to the directory.
dsadd ou /? - help for adding an organizational unit to the directory.
dsadd user /? - help for adding a user to the directory.
dsadd quota /? - help for adding a quota to the directory.

Directory Service command-line tools help:
dsadd /? - help for adding objects.
dsget /? - help for displaying objects.
dsmod /? - help for modifying objects.
dsmove /? - help for moving objects.
dsquery /? - help for finding objects matching search criteria.
dsrm /? - help for deleting objects.
dsadd failed:The parameter is incorrect.
type dsadd /? for help.

Hide comments


  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.