Skip to content
Menu
The Lonely Administrator
  • PowerShell Tips & Tricks
  • Books & Training
  • Essential PowerShell Learning Resources
  • Privacy Policy
  • About Me
The Lonely Administrator

Create New Computer with ADSI

Posted on February 19, 2011September 12, 2022

UPDATE 12 Sept. 2022: In attempting to correct obsolete information( this was originally published in 2011), I removed the contents of this post. But I did manage to save the function, which is all you probably care about anyway.

Manage and Report Active Directory, Exchange and Microsoft 365 with
ManageEngine ADManager Plus - Download Free Trial

Exclusive offer on ADManager Plus for US and UK regions. Claim now!

Behind the PowerShell Pipeline
Function New-Computer {
  Param(
 [string]$name=$(Throw "You must enter a computer name."),
 [string]$Path="CN=Computers,DC=MyCompany,DC=Local",
 [string]$description="Company Server",
 [switch]$enabled
)

[ADSI]$OU="LDAP://$Path"
#set name to all uppercase
$name=$name.ToUpper()

$computer=$OU.Create("computer","CN=$name")
$computer.Put("SamAccountName","$name$")
$computer.put("Description",$description)
if ($enabled) {
$computer.Put("UserAccountControl",4128)
} else {
$computer.Put("UserAccountControl",4130)
}

$computer.SetInfo()
} #end function

Share this:

  • Click to share on X (Opens in new window) X
  • Click to share on Facebook (Opens in new window) Facebook
  • Click to share on Mastodon (Opens in new window) Mastodon
  • Click to share on LinkedIn (Opens in new window) LinkedIn
  • Click to share on Pocket (Opens in new window) Pocket
  • Click to share on Reddit (Opens in new window) Reddit
  • Click to print (Opens in new window) Print
  • Click to email a link to a friend (Opens in new window) Email

Like this:

Like Loading...

Related

2 thoughts on “Create New Computer with ADSI”

  1. Pingback: Tweets that mention Create New Computer with ADSI | The Lonely Administrator -- Topsy.com
  2. Pingback: Tweets that mention Create New Computer with ADSI | The Lonely Administrator -- Topsy.com

Comments are closed.

reports

Powered by Buttondown.

Join me on Mastodon

The PowerShell Practice Primer
Learn PowerShell in a Month of Lunches Fourth edition


Get More PowerShell Books

Other Online Content

github



PluralSightAuthor

Active Directory ADSI Automation Backup Books CIM CLI conferences console Friday Fun FridayFun Function functions Get-WMIObject GitHub hashtable HTML Hyper-V Iron Scripter ISE Measure-Object module modules MrRoboto new-object objects Out-Gridview Pipeline PowerShell PowerShell ISE Profile prompt Registry Regular Expressions remoting SAPIEN ScriptBlock Scripting Techmentor Training VBScript WMI WPF Write-Host xml

©2025 The Lonely Administrator | Powered by SuperbThemes!
%d