locked
Another Computer Renaming Question RRS feed

  • Question

  • I know there are a thousand threads on this topic. I have gone over so many of them, but have not found what I am needing. So, I figured I would ask. 

    Here is my situation:

    We are deploying 500 new Windows 7 Pro laptops with a pre-loaded image. I have used AIK to tweak the settings i want, and then I am sysprepping using the unattended answer file to automatically join the domain. That works fine using a PowerShell script, but I can not figure out how to change the computer name based on our naming schema. It must use our three letter prefix, followed by the serial number. So, xxxYYYYYYY. I would love to have it do this using PowerShell if possible. Any help would be greatly appreciated.


    Friday, May 20, 2011 1:57 AM

Answers

  • If you remove the computername from your unattend.xml then it will prompt you.

    However, as said above - use the Microsoft Deployment Toolkit and save yourself all this work.

    There's a great video walkthrough series here.

    Monday, May 30, 2011 9:16 AM

All replies

  • For a deployment this large I would be using something like Microsoft Deployment Toolkit or SCCM. Either of those tools give you the option to automate the naming process. They include built in scripts that will do this and more.
    Friday, May 20, 2011 3:30 AM
  • i dont know if you would like to to this over the network.
    but for local actions

    i got this:
    (havnt tested it! jsut wrote it in few minutes)

    #### Variables ####
    #gets the COmputer system object
    $Computer = Get-WmiObject Win32_ComputerSystem
    #gets the actual name of the computer
    $OldName = $Computer.Name
    #gets the Bios object
    $Bios = get-wmiobject win32_bios
    #gets the serial number from the bios
    $SerialNumber = $Bios.SerialNumber
    #generates here the new name you like
    $NewName = '[letter1]' + '[letter2]' + '[letter3]' + $SerialNumber.replace(' ','')
    
    #### Script actions ####
    #renames the computer
    $Computer.Rename($NewName)
    
    #checks if the computer name realy has been changed
    if($Computer.name -eq $NewName){
    	Write-Host 'Computer succesfully renamed'
    }
    else{
    	Write-Host 'Computer not renamed'
    }
    	
    
    

    • Proposed as answer by HH.Scripting Friday, May 20, 2011 11:05 AM
    Friday, May 20, 2011 9:00 AM
  • That script seems to work as long as it's not on the domain. Is there a way to add a way to get it to use domain credentials as well?

     

    Great work for writing that script in a few minutes.

    Friday, May 20, 2011 2:48 PM
  • What do you mean with "not on the daomain"?

    how do you use it? =)

    Friday, May 20, 2011 2:57 PM
  • Well, if the computer is not on the domain, it changes the name of the computer. I am afraid that for whatever reason it is joining the domain first, and then renaming the computer which requires domain credentials to do so. I have the rename.ps1 script set to run before the joindomain.ps1 script, but it joins the domain without renaming the laptop.
    Friday, May 20, 2011 3:36 PM
  • On what for OS are you running the script?
    Friday, May 20, 2011 3:52 PM
  • Windows 7 Pro
    Friday, May 20, 2011 4:08 PM
  • excuse my for the time taking to reply! but iw as busy =)

    well, it could be that you need to be local administrator. or to accept the uac prompt.

    i cant tell you for sure, cause i cant test it. but it would be a possible reason for the failure.

     

    try to runt he script with right click --> run as Administrator if it works then its the reason.

    Wednesday, May 25, 2011 5:58 AM
  • The script works fine when I run it by itself or if it is the only script setup to run in the unattended answer file. When I have both the rename script and the join domain script set to run in the answer file, it only joins the domain. I'm not sure what sort of conflict is occurring, but for now I just have it setup to ask for the computer name during the unattended setup and then it joins the domain. It would be nice to have it do both using the unattended answer file, but this will work as well.

     

    I understand you being busy, my job loves meetings like no other.

    Wednesday, May 25, 2011 1:53 PM
  • It sounds like the join happens before the attempt to rename. Is it possible you don't have control over the order in which the scripts run? Can you revise the scripts to log the date/time when they start and finish, perhaps to a local file, so you can confirm which script runs first. Possibly, the rename starts first, but completes after the join script. If the rename script never completes, maybe there is an error that you can trap and log (perhaps a permissions problem).

    The other possibility is that a pause is required between the scripts for some reason. You could use Start-Sleep.

     


    Richard Mueller - MVP Directory Services
    Friday, May 27, 2011 6:05 PM
  • If you remove the computername from your unattend.xml then it will prompt you.

    However, as said above - use the Microsoft Deployment Toolkit and save yourself all this work.

    There's a great video walkthrough series here.

    Monday, May 30, 2011 9:16 AM