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!
ManageEngine ADManager Plus - Download Free Trial
Exclusive offer on ADManager Plus for US and UK regions. Claim now!
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
2 thoughts on “Create New Computer with ADSI”
Comments are closed.