Create Active Directory Computer Object

This code demonstrates how to create a new computer object on Active Directory without any plug-ins.

3.8 Star
Add to favorites
Active Directory
E-mail Twitter Digg Facebook
  • This is great but can it also do...
    2 Posts | Last post November 21, 2013
    • Here is our situation:
      We use CM12 and OSD and ,OSD (CM12 in general) is tied tightly to AD group objects.
      Wee need to pre-populate computers AD so that when CM12 scans a given OU it then sees 
      that computer name and pulls it into CM12.
      Then when a tech performs a PXE OSD build the system should not be considered an unknown computer and just build the TS selected without being prompted for a hostname.  We do not let teh system auto name as MININT- will not work well in our environment.
      This is not happening with our new computers only those that have been in the domain already.
      The issue is that MSFT has removed the ability to add a PC to the domain using the guid section, basicly enabling the option to be a managed computer, to tie the physical hardware to AD and as result to CM12.
      Technically, it can be done but ONLY if you are on a server that has WDS enabled and not via spreadsheet (at least not that I could find).
      Having the ability to do this would GREATLY increase the success rate of the auto deployment of apps during the OSD process and speed up overall delivery of a PC to a user.
      Many Thanks in advance for any info you can provide.
      Roger Truss
      Windows Administrator
      Brunswick Corporation
    • Hi Roger,
      I believe this question should go to someone in Change Manager 2012 for the assistance you need or to the Windows Deployment Server team.  This is because I don't used these products. 
  • Automating the creation of computer accounts
    3 Posts | Last post November 05, 2012
    • The script describes in full how to create a single computer account.
      I'd like to automate a creation of computer objects in AD, based on user names; preferrably using an input from a CSV file.
      For example, 
      foreach $sAMAccountName
         $computername = $displayname&"-PC"
      Sorry if this is somewhat mistakenly written, I'm just starting in PowerShell.
      Thanks in advance.
    • Thank you.
    • Hi Serhad,
      I'll try my best to answer the question. Some characters do not display correctly within this area when typing code so bare with me.  I haven't tested the code but it should work.  If you have issues let me know.  Please test the code with two test computer names to see if it works before proceeding.  
      1.)Create a csv file in notepad and save it as "ComputerList.csv" on your C drive
      2.)Still in notepad, Type in "name" on the first line.
      3.)On each line after that, add the computer names you want to create, one computer name per line.
      Example ComputerList.csv File:
      Now for the powershell code part.
      4.) Create a function called CreateComputer at the top of your script.  PowerShell functions must be at the top of the script before you call them.
      5.) Basically, place the code from this website in this function.
      6.) Now write the code below this function importing csv file and looping through the names.
      Powershell Code Example:
      Function CreateComputer 
      $ComputerName = $args[0]
      $objDomain = New-Object System.DirectoryServices.DirectoryEntry 
      $objComputer = $objDomain.Create("computer", "CN=" + $ComputerName) 
      $objComputer.Put("sAMAccountName",$ComputerName + "$") # A dollar sign must be appended to the end of every computer sAMAccountName. 
      $objComputer.Put("Description","Some Descriptive text") 
      $objComputer.Put("userAccountControl", 4128) 
      $Computers = Import-Csv -Path "C:\ComputerListFile.csv"
      foreach ($Computer in $Computers)
        CreateComputer $Computer.Name