1 2 Previous Next 15 Replies Latest reply on Jan 17, 2017 5:12 PM by dsears

    I want to change the naming convention for PCs imaged from within a particular "My Tasks" tree.

    Rookie

      Currently it is a generic name given to PCs, but i was wondering if i can change it to have a partially set name (beginning with AU) as well as a section given via IP address (if IP address 172.20 then add in aa) and then another set name (NB for notebook) and then the machines service tag name. Is that possible?

       

      So currently the name is companyname-randomlettersandnumbers

       

      I want to change it for PCs placed from Bare Metal Rebuild into: My Tasks -> Task A Group so the name would be: AU<location code>NBservicetagofpc

        • 1. Re: I want to change the naming convention for PCs imaged from within a particular "My Tasks" tree.
          Apprentice

          I have an AutoIt script that renames systems using a combination of netdom.exe and powershell commands. If you would like, I can send a generic copy of that script to you to look at?

          • 2. Re: I want to change the naming convention for PCs imaged from within a particular "My Tasks" tree.
            carlos Expert

            The only way I know you can do this is using the Device Name Prompter in a provisioning Task. See the picture. (It took me a while to get this info...)

            Dludwig, I'm very interested on seeing the Script you mentioned as well 

            Capture.JPG

            • 3. Re: I want to change the naming convention for PCs imaged from within a particular "My Tasks" tree.
              Rookie

              G'day DLudwig, that would be much appreciated please :-)

               

              And thank you Carlos, i will check that out today.

              • 4. Re: I want to change the naming convention for PCs imaged from within a particular "My Tasks" tree.
                phoffmann SupportEmployee

                dsears - if you want, you can just include it here. Just respond, use the "advanced editor" option....

                Advanced_Editor.jpg

                 

                ... and either include a code-block ... (chosing "plain" as we don't have AutoIT syntax highlighting)

                CodeBlockHighlighting.jpg

                 

                ... or attach a file (zipped, ideally) - which is usually hidden/overlooked at the bottom right of the response side of things.

                AttachingFiles.jpg

                 

                I personally prefer to either do both, or just the former, as copy & pasting stuff is more easy to find.

                 

                Would be nice to have a look at the relevant script you're talking about ... (another advantage of the "copy & paste" ease is just seeing the script block & then adapting it to once's own preferred scripting language or whatnot).

                • 5. Re: I want to change the naming convention for PCs imaged from within a particular "My Tasks" tree.
                  Apprentice
                  #RequireAdmin
                  #Region ;**** Directives created by AutoIt3Wrapper_GUI ****
                  #AutoIt3Wrapper_Icon=C:\Program Files (x86)\AutoIt3\Icons\au3.ico
                  #AutoIt3Wrapper_Outfile_x64=C:\Temp\RenameComputer.exe
                  #AutoIt3Wrapper_UseX64=y
                  #AutoIt3Wrapper_Res_Description=Rename computer based on commandline arguements
                  #AutoIt3Wrapper_Res_Fileversion=0.0.0.30
                  #AutoIt3Wrapper_Res_Fileversion_AutoIncrement=y
                  #AutoIt3Wrapper_Res_requestedExecutionLevel=asInvoker
                  #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
                  
                  
                  Global $LogFile, $RenameComp, $Version
                  Global $Prefix, $SN, $Suffix
                  
                  
                  $LogFile = FileOpen("C:\Logs\RenameComputer.log", 9)
                  
                    FileWriteLine($LogFile, "---------------------------------------------------------------------------------START---------------------------------------------------------------------------------" & @CRLF)
                  
                  
                  ;Check for administrative privileges
                    FileWriteLine($LogFile, @MON & "-" & @MDAY & "-" & @YEAR & " " & @HOUR & ":" & @MIN & ":" & @SEC & " Checking for administrative permissions." & @CRLF)
                  If IsAdmin() Then
                    FileWriteLine($LogFile, @MON & "-" & @MDAY & "-" & @YEAR & " " & @HOUR & ":" & @MIN & ":" & @SEC & " Administrative permissions exist." & @CRLF)
                  Else
                    FileWriteLine($LogFile, @MON & "-" & @MDAY & "-" & @YEAR & " " & @HOUR & ":" & @MIN & ":" & @SEC & " Administrative permissions do not exist." & @CRLF)
                    FileWriteLine($LogFile, "----------------------------------------------------------------------------------END----------------------------------------------------------------------------------" & @CRLF)
                    FileWriteLine($LogFile, @CRLF)
                    FileClose($LogFile)
                    MsgBox(0, "Check Admin rights", "Please launch the script with an account with local administrative rights.", 10)
                    Exit(5)
                  EndIf
                  
                  
                  ;Extract required files if they don't exist
                    FileWriteLine($LogFile, @MON & "-" & @MDAY & "-" & @YEAR & " " & @HOUR & ":" & @MIN & ":" & @SEC & " Checking if required files exist." & @CRLF)
                  If FileExists("C:\Windows\System32\en-US\netdom.exe.mui") = 0 Or FileExists("C:\Windows\System32\netdom.exe") = 0 Then
                    If FileExists("C:\Windows\System32\en-US\netdom.exe.mui") = 0 Then
                    FileWriteLine($LogFile, @MON & "-" & @MDAY & "-" & @YEAR & " " & @HOUR & ":" & @MIN & ":" & @SEC & " C:\Windows\System32\en-US\netdom.exe.mui did not exist. Extracting file to C:\Windows\System32\en-US\netdom.exe.mui and C:\Windows\SysWOW64\en-US\" & @CRLF)
                    FileInstall("C:\Windows\System32\en-US\netdom.exe.mui", "C:\Windows\System32\en-US\netdom.exe.mui", 0)
                    FileCopy("C:\Windows\System32\en-US\netdom.exe.mui", "C:\Windows\SysWOW64\en-US\netdom.exe.mui", 0)
                  EndIf
                    If FileExists("C:\Windows\System32\netdom.exe") = 0 Then
                    FileWriteLine($LogFile, @MON & "-" & @MDAY & "-" & @YEAR & " " & @HOUR & ":" & @MIN & ":" & @SEC & " C:\Windows\System32\netdom.exe did not exist. Extracting file to C:\Windows\System32\ and C:\Windows\SysWOW64\" & @CRLF)
                    FileInstall("C:\Windows\System32\netdom.exe", "C:\Windows\System32\netdom.exe", 0)
                    FileCopy("C:\Windows\System32\netdom.exe", "C:\Windows\SysWOW64\netdom.exe", 0)
                    EndIf
                  Else
                    FileWriteLine($LogFile, @MON & "-" & @MDAY & "-" & @YEAR & " " & @HOUR & ":" & @MIN & ":" & @SEC & " Required files exist." & @CRLF)
                  EndIf
                  
                  ;Set prefix based on command line or lack of command line (default to 000)
                  If $CMDLINE[0] > 0 Then
                    $Prefix = $CMDLINE[1] ;Set by commandline
                  Else
                    $Prefix = "000" ;Default if not commandline
                  EndIf
                  
                  
                  ;Retrieve Serial Number from BIOS and store as variable
                    FileWriteLine($LogFile, @MON & "-" & @MDAY & "-" & @YEAR & " " & @HOUR & ":" & @MIN & ":" & @SEC & " Executing Powershell command line to retrieve Serial Number" & @CRLF)
                  ShellExecuteWait("C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe", '-command "Get-WmiObject win32_bios | Select SerialNumber > C:\Logs\SerialNumber.txt"', "", "", @SW_HIDE)
                  $SN = FileReadLine("C:\Logs\SerialNumber.txt", 4)
                  FileDelete("C:\Logs\SerialNumber.txt")
                  $SN = StringStripWS($SN, 8)
                  If @error <> 0 Then
                    FileWriteLine($LogFile, @MON & "-" & @MDAY & "-" & @YEAR & " " & @HOUR & ":" & @MIN & ":" & @SEC & " System Serial Number not found. Exiting script." & @CRLF)
                    FileWriteLine($LogFile, "----------------------------------------------------------------------------------END----------------------------------------------------------------------------------" & @CRLF)
                    FileWriteLine($LogFile, @CRLF)
                    FileClose($LogFile)
                    Exit(5)
                  Else
                    FileWriteLine($LogFile, @MON & "-" & @MDAY & "-" & @YEAR & " " & @HOUR & ":" & @MIN & ":" & @SEC & " System Serial Number - " & $SN & @CRLF)
                  EndIf
                  
                  
                  ;Detect desktop, laptop, VM and set correct suffix
                    FileWriteLine($LogFile, @MON & "-" & @MDAY & "-" & @YEAR & " " & @HOUR & ":" & @MIN & ":" & @SEC & " Executing powershell to detect whether system is a desktop, laptop or vm for correct suffix assignment." & @CRLF)
                  ShellExecuteWait("C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe", '-command "Get-WmiObject win32_ComputerSystemProduct | Select Version > C:\Logs\Version.txt"', "", "", @SW_HIDE)
                  $Version = FileReadLine("C:\Logs\Version.txt", 4)
                  FileDelete("C:\Logs\Version.txt")
                  $Version = StringStripWS($Version, 3)
                  If @error <> 0 Then
                    FileWriteLine($LogFile, @MON & "-" & @MDAY & "-" & @YEAR & " " & @HOUR & ":" & @MIN & ":" & @SEC & " System version not found. Exiting script." & @CRLF)
                    FileWriteLine($LogFile, "----------------------------------------------------------------------------------END----------------------------------------------------------------------------------" & @CRLF)
                    FileWriteLine($LogFile, @CRLF)
                    FileClose($LogFile)
                    Exit(5)
                  Else
                    FileWriteLine($LogFile, @MON & "-" & @MDAY & "-" & @YEAR & " " & @HOUR & ":" & @MIN & ":" & @SEC & " System Version - " & $Version & @CRLF)
                  EndIf
                  
                  
                  ;Set suffix based on hardware type (Lenovo hardware or Vmware)
                  If $Version = "None" Then
                    If StringLeft($SN, 6) = "VMware" Then
                    FileWriteLine($LogFile, @MON & "-" & @MDAY & "-" & @YEAR & " " & @HOUR & ":" & @MIN & ":" & @SEC & " Detected system is a VM. Setting suffix to VM" & @CRLF)
                    $Suffix = "VM"
                    Else
                    FileWriteLine($LogFile, @MON & "-" & @MDAY & "-" & @YEAR & " " & @HOUR & ":" & @MIN & ":" & @SEC & " Unable to detect model based on system version correctly. Detected Version - " & $Version[1] & " " & $Version[2] & ". Setting suffix to U" & @CRLF)
                    $Suffix = "U"
                    EndIf
                  Else
                    $Version = StringSplit(StringStripWS($Version,3)," ") ;Detect whether system is desktop, laptop, or unknown based on Lenovo system information
                    If $Version[1] = "ThinkCentre" Or $Version[1] = "ThinkStation" Then
                    FileWriteLine($LogFile, @MON & "-" & @MDAY & "-" & @YEAR & " " & @HOUR & ":" & @MIN & ":" & @SEC & " Detected system is a Desktop. Setting suffix to W" & @CRLF)
                    $Suffix = "W"
                    ElseIf $Version = "ThinkPad" Then
                    FileWriteLine($LogFile, @MON & "-" & @MDAY & "-" & @YEAR & " " & @HOUR & ":" & @MIN & ":" & @SEC & " Detected system is a Laptop. Setting suffix to L" & @CRLF)
                    $Suffix = "L"
                    Else
                    FileWriteLine($LogFile, @MON & "-" & @MDAY & "-" & @YEAR & " " & @HOUR & ":" & @MIN & ":" & @SEC & " Unable to detect model based on system version correctly. Detected Version - " & $Version[1] & " " & $Version[2] & ". Setting suffix to U" & @CRLF)
                    $Suffix = "U"
                    EndIf
                  EndIf
                  
                  
                  ;Run netdom.exe command line to rename the computer if it is not a VM
                  If $Suffix <> "VM" Then
                    FileWriteLine($LogFile, @MON & "-" & @MDAY & "-" & @YEAR & " " & @HOUR & ":" & @MIN & ":" & @SEC & " New computer name will be - " & $Prefix & $SN & $Suffix & ".trtc.com" & @CRLF)
                    FileWriteLine($LogFile, @MON & "-" & @MDAY & "-" & @YEAR & " " & @HOUR & ":" & @MIN & ":" & @SEC & " Starting rename operation." & @CRLF)
                    $RenameComp = RunWait("C:\Windows\System32\netdom.exe renamecomputer " & @ComputerName & " /newname:" & $Prefix & $SN & $Suffix & " /force", "", @SW_HIDE)
                    If $RenameComp <> 0 Then
                    FileWriteLine($LogFile, @MON & "-" & @MDAY & "-" & @YEAR & " " & @HOUR & ":" & @MIN & ":" & @SEC & " Rename operation failed. Exit code - " & $RenameComp & @CRLF)
                    FileWriteLine($LogFile, "----------------------------------------------------------------------------------END----------------------------------------------------------------------------------" & @CRLF)
                    FileWriteLine($LogFile, @CRLF)
                    FileClose($LogFile)
                    Exit(5)
                    Else
                    FileWriteLine($LogFile, @MON & "-" & @MDAY & "-" & @YEAR & " " & @HOUR & ":" & @MIN & ":" & @SEC & " Rename operation finished successfully. A reboot is required to finish rename. Exit code - " & $RenameComp & @CRLF)
                    EndIf
                  Else
                    FileWriteLine($LogFile, @MON & "-" & @MDAY & "-" & @YEAR & " " & @HOUR & ":" & @MIN & ":" & @SEC & " Detected system is a VM. Skipping rename operation." & @CRLF)
                  EndIf
                  
                  
                  ;Initiate reboot
                  OnAutoItExitRegister("RebootFunc")
                  
                  Exit(100)
                  
                  Func RebootFunc()
                    FileWriteLine($LogFile, @MON & "-" & @MDAY & "-" & @YEAR & " " & @HOUR & ":" & @MIN & ":" & @SEC & " Initiating reboot to compplete rename operation." & @CRLF)
                    FileWriteLine($LogFile, "----------------------------------------------------------------------------------END----------------------------------------------------------------------------------" & @CRLF)
                    FileWriteLine($LogFile, @CRLF)
                    FileClose($LogFile)
                    Sleep(10000)
                    Shutdown(22) ;Force a reboot
                  EndFunc
                  

                   

                  Here's the code everyone. It does require that you download RSAT to retrieve netdom.exe (not sure if I'm allowed to attach netdom.exe as it's not my property).

                  1 of 1 people found this helpful
                  • 6. Re: I want to change the naming convention for PCs imaged from within a particular "My Tasks" tree.
                    phoffmann SupportEmployee

                    Cool - thanks for sharing.

                     

                    And you made absolutely the right call on not attaching NETDOM ... best to err on the side of caution. We don't want to accidentally be bypassing EULA's or whatnot.

                     

                    Thank you kindly! 

                    • 7. Re: I want to change the naming convention for PCs imaged from within a particular "My Tasks" tree.
                      Apprentice

                      I tr to err on the side of caution.... I also tried to make sure I pulled out company specific stuff although this script didn't have much of that other than copyright information (which is more of a formality than legal as I own the code). If you happen to see something company specific (server names or anything), let me know so I can pull it out.

                      • 8. Re: I want to change the naming convention for PCs imaged from within a particular "My Tasks" tree.
                        carlos Expert

                        I tried to use the script, but I cant run it.

                        How do you use it? Under which environment do you run it?

                        I got the netdom.exe from here: Download Windows XP Service Pack 2 Support Tools from Official Microsoft Download Center

                        But still I can not run the script, it is in a au3 format, I tried changing it to .bat but obviously doesn't work.

                         

                        -CS

                        • 9. Re: I want to change the naming convention for PCs imaged from within a particular "My Tasks" tree.
                          Apprentice

                          So I would recommend downloading this version as this is what I used https://www.microsoft.com/en-us/download/details.aspx?displaylang=en&id=7887 (Windows 7 SP1 version)

                           

                          As far as using the script goes, you will need to install AutoIt on your computer and compile the script into an executable.

                           

                          Process:

                          Download AutoIt (https://www.autoitscript.com/cgi-bin/getfile.pl?autoit3/autoit-v3-setup.exe  )

                          Install AutoIt

                          Install RSAT (https://www.microsoft.com/en-us/download/details.aspx?displaylang=en&id=7887 )

                          Copy the netdom.exe.mui from the RSAT install to C:\Windows\System32\en-US\

                          Copy the netdom.exe fromk the RSAT install to C:\Windows\System32\

                          Compile the script (the exe will be in the same directory as the .au3 file)

                           

                          At this point you can run it straight on any Windows 7 or higher computer. Keep in mind it will force a reboot.

                           

                          This particular script has some naming conventions set in it. If you don't have any scripting/programming background, I can help you put something together to work for what you want.

                           

                           

                          If you want to circumvent AutoIt entirely... You can read through the script to see what it's doing and write in a scripting language of your choice (VB, Powershell, etc.). AutoIt itself is really just a shell for VBS with the ability to compile to executable.

                          • 10. Re: I want to change the naming convention for PCs imaged from within a particular "My Tasks" tree.
                            carlos Expert

                            I see, that worked. Tnx.

                            In my case, I needed to rename the PC during provisioning. But it is a nice tool (AutoIT) and script.

                            Thanks.

                            • 11. Re: I want to change the naming convention for PCs imaged from within a particular "My Tasks" tree.
                              Apprentice

                              If you want to explain what exactly it is you need to, i may be able to help. I'm pretty creative when it comes to Provisioning and scripting.

                              • 12. Re: I want to change the naming convention for PCs imaged from within a particular "My Tasks" tree.
                                carlos Expert

                                I wanted for the OS to ask for a new Name after sysprep (then capturing an image, and then redeploy) , just as OOBE, but I could not get it to work and I ended up using the Device Name Prompter.

                                • 13. Re: I want to change the naming convention for PCs imaged from within a particular "My Tasks" tree.
                                  Apprentice

                                  Do you want the computer to actually get renamed? What do you want to happen with the name? I could modify the script to pop-up a prompt very easily. instead of calculating anything (maybe 20-30 lines total - 5 minutes of time). I would just need to know what you're trying to do with it.

                                  • 14. Re: I want to change the naming convention for PCs imaged from within a particular "My Tasks" tree.
                                    carlos Expert

                                    I would like the UI to prompt for a new name tnx!

                                    1 2 Previous Next