Here is the Active Directory cmdlet to create computer objects in your
domain. Note, the verb is 'New' (and not 'Add' and the noun is
'AdComputer' not plain Computer.
If you are new to configuring Active Directory with PowerShell, then I recommend you
look at the
basics with
Get-AdUser.
a)
Logon: At a Domain Controller b) Find: Active Directory Module for Windows PowerShell
c) Launch: The PowerShell
executable d) Run: Import-Module activedirectory
The New-AdComputer syntax is more straightforward than Get-AdComputer,
the key is deciding which LDAP properties to include in your script.
In this example we only use 'SamAccountName' and 'name', later examples
include 'location' and 'enable'.
Note 2: The purpose of incrementing the $i variable is
so that you can run the script again and again without error.
Guy Recommends: SolarWinds' Free Bulk Import Tool
Import users from a spreadsheet. Just provide a list of the
users with their fields in the
top row, and save as .csv file. Then launch this FREE utility and match
your fields with AD's
attributes, click to import the users. Optionally, you can
provide the name of the OU where the new accounts will be born.
There are also two bonus tools in this free download, and all 3 have been approved by Microsoft:
I love employing loops in PowerShell, it makes scripting repetetive jobs so
worthwhile. This example creates ten new computers, and hopefully,
gives you ideas for bulk creating accounts.
If you cannot get these PowerShell examples to work, instead you get a message saying: The term
'New-AdComputer' is not recognized ..... then I suggest you
troubleshoot with these two commands:
# PowerShell Check for Active Directory Services Get-Service ad*
Get-Module
If you suspect that the Active Directory Module for Windows
PowerShell has not loaded, then see more about
installing activedirectory modules.
Learn About New-AdComputer With
Get-Help -full
This is how I discovered the -enable and -location parameters.
Note 3: Amongst the zillions of parameters you maybe
interested in trying -passThru. What it does is display information
about the object(s) that you have just created.
Researching
Similar Active Directory Cmdlets
Once you have mastered Get-AdComputer and New-AdComputer, you may wish to know more about
similar active directory tools. To obtain a comprehensive list of the AD
cmdlets try this command:
Note 4: Naturally, you can also use these verbs and nouns in
other combinations.
»
Summary of PowerShell New-AdComputer
New-AdComputer is lovely way to create computer accounts in Active
Directory. It pays to research the available LDAP properties. If you are new to
PowerShell's active directory cmdlets take the time to
check the basics.
If you like this page then please share it with your friends
Please email me if you have a better example script. Also please report any factual mistakes, grammatical errors or broken links, I will be happy to correct the fault.
Windows Management Instrumentation (WMI) is one of the hidden
treasures of Microsoft operating systems.
Fortunately, SolarWinds
have created the
Free WMI Monitor so that you can actually see and understand these gems of
performance information. Take the guess work out of which
WMI counters to use for applications like Microsoft Active Directory,
SQL or Exchange Server.