PowerShell New-AdComputer

Windows PowerShell New-AdComputer CmdletPowerShell New-AdComputer

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.

Topics PowerShell New-AdComputer

 ♣

Preparation: Checklist for New-AdComputer

a) Logon: At a Domain Controller
b) Find: Active Directory Module for Windows PowerShell
c) Launch: The PowerShell executable
d) Run: Import-Module activedirectory

Example 1: New-AdComputer

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

# PowerShell New-AdComputer example
$Box "OU=Raglan,DC=burrium,DC=usk"
$Label ="Head Office"
New-AdComputer -name $Label -SamAccountName $Label -Path $Box

Note 1:  I have introduced the variables $Box and $Label so that you will give thought to the names of your new computers.

Example 2: New-AdComputer -enable and -location

This example makes the computers ready for use with -enable $True.  It also sets the value of the LDAP location property to "London".

# PowerShell New-AdComputer Cmdlet
$Box "OU=Raglan,DC=burrium,DC=usk"
$Label ="Head Office" + $i
New-AdComputer -name $Label -SamAccountName $Label -Path $Box`
-enable $True -location "London"
$i ++

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 ToolFree Download Solarwinds 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 and import the users.

Optionally, you can provide the name of the OU where the new accounts will be born. Download your FREE bulk import tool.

If you need more comprehensive application analysis software,
Download a free trial of SAM (Server & Application Monitor)

Example 3: New-AdComputer – Batch of Accounts

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.

Clear-host
foreach ($number in 1..10 )
{
$Box "OU=Raglan,DC=burrium,DC=usk"
$Label ="Head Office" + $i
New-AdComputer -name $Label -SamAccountName $Label -Path $Box `
-enable $True -location "London"
$i ++

}

Troubleshooting New-AdComputer

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.

# PowerShell New-AdComputer examples
Clear-Host
Get-Help New-AdComputer -full

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.

Guy Recommends:  A Free Trial of the Network Performance Monitor (NPM)Review of Orion NPM v11.5 v11.5

SolarWinds’ Network Performance Monitor will help you discover what’s happening on your network.  This utility will also guide you through troubleshooting; the dashboard will indicate whether the root cause is a broken link, faulty equipment or resource overload.

What I like best is the way NPM suggests solutions to network problems.  Its also has the ability to monitor the health of individual VMware virtual machines.  If you are interested in troubleshooting, and creating network maps, then I recommend that you try NPM now.

Download a free trial of Solarwinds’ Network Performance Monitor

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:

Clear-Host
Get-Command -Noun ad*

Amongst the results you should see these cmdlets:

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

 


See more PowerShell Active Directory Cmdlets

PowerShell Home  • Get-AdUser -filter  • Get-AdUser  • New-AdUser  • Get-AdComputer

Export-CSV  • Import CSV  • PowerShell Active Directory  • New-AdComputer

PowerShell Codeplex  • PowerShell Ad Cmdlets  • Free Import User CSVDE Tool

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.