Guy recommends :
Free SolarWinds
VM Console

Solarwinds VM Console Free Download

Find out which of your VMs are a waste of space and which VMs need more resources.



PowerShell New-AdComputer

Windows PowerShell New-AdComputerPowerShell 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 example
$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 of 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 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:

  1. Bulk-import new users into Active Directory.
  2. Seek and zap unwanted user accounts.
  3. Find inactive computers.

Download your FREE bulk import tool.

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.

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:

  • Add-AdGroupmember
  • Enable-AdAccount
  • Get-AdComputer
  • Move-AdComputer
  • New-AdUser
  • Set-AdUser
  • Remove-AdGroup
  • UnLock-AdAccount

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-AdComputer

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

PowerShell Codeplex  • PowerShell Ad Cmdlets  • Get-AdComputer

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.

Download my ebook:Getting Started with PowerShell
Getting Started with PowerShell - only $9.25

You get 36 topics organized into these 3 sections:
   1) Getting Started
   2) Real-life tasks
   3) Examples of Syntax.

In addition to the ebook, you get a PDF version of this  Introduction to PowerShell ebook  It runs to 120 pages of A4.

 *


Custom Search

Site Home

Guy Recommends: WMI Monitor and It's Free!Solarwinds WMI Monitor

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.

Download your free copy of WMI Monitor

Author: Guy Thomas Copyright © 1999-2012 Computer Performance LTD All rights reserved.

Please report a broken link, or an error to: