1 2 Previous Next 15 Replies Latest reply on Nov 19, 2014 5:48 AM by joe.denice

    Script during Provisioning to return a Variable

    Apprentice

      Hello,

       

      With other deployment products, I have been able to run a script during the provisioning process and have the result returned to the process.

       

      Essentially what I need to do is --

      • Inject a script onto the PC being imaged
      • Execute the script which will query WMI for a variable such as the Serial Number
      • Return that variable to LD
      • Copy the variable or the value to a file on the PC being image, such as the "unattend.xml"

       

      My immeditate need is to capture the Serial Number and use it in the unattend.xml for the PC name.

       

      Is anyone doing something similar that you can share?

       

      I am deploying large numbers of systems that have never been in LD so there is database data for them.  There is no way I can expect anyone to write spreadsheets or anything like that to handle what should be a very simple automated process.

       

      Thanks!

        • 1. Re: Script during Provisioning to return a Variable
          Apprentice

          So - if it's not possible to do this in this manner, has anyone figured out how to use a Serial Number in the naming of the PC?  I would prefer not to rename if possible since it requires more reboots and time.

           

          Thanks

          • 2. Re: Script during Provisioning to return a Variable
            davidg5700 Specialist

            What I am doing is letting the unattend create a machine name and join it to the domain.  In the system configuration section of the provisioning template I am running a script that queries WMI for the serial number and uses that to look up the warranty information and write that to the computer account description.  The script also renames the computer account and moves it to a chosen OU. 

             

            I would think that you could modify this process to pull the serial number and rename the computer with that.  You could skip the final reboot to put in place the final renaming and let the LD database catch up to the rename on a subsequent inventory scan.  You will see a bunch of funky names in the console for a brief period, but they will correct themselves.

            • 3. Re: Script during Provisioning to return a Variable
              Apprentice

              Thanks for the reply David

               

              Since I wasn't getting any feedback I decided to try something similar to your recommendation.

               

              I added a automatic name "*" and join domain to my unattend.xml.

               

              Then I set up System Configuration items to do the following:

              • Copy the WSName.exe app to the system drive
              • Run wsname.exe with switches to rename a domain PC
              • Delete wsname.exe
              • Restart

               

              While not ideal, I figured I could move forward and try to get ideal later.

               

              Unfortunately after a reboot in the sysprep process the system just stops the Provisioning process.

               

              I verified that the ldprovisioning folder was created on the imaged drive before it rebooted, SetupComplete.cmd is being created properly.

               

              After it stops running I log in, and look for the ldprovisioning directory and it is not present.  SetupComplete.cmd is still present and unattend.xml is still present.

               

              Thanks

               

              Capture.JPG

               

              Message was edited - added screen print

              • 4. Re: Script during Provisioning to return a Variable
                marcel Specialist

                Why You dont do this in WinPe? We have create a WinPe Action that modified unattend.xml before booting - this works really good and you dont need actions in system configuration.

                • 5. Re: Script during Provisioning to return a Variable
                  Apprentice

                  Marcel,

                  That is exactly what I want to do, but have been unsuccessful.  If you can share your method, it would be greatly appreciated.

                   

                  Thanks!

                  • 6. Re: Script during Provisioning to return a Variable
                    marcel Specialist

                    I could script it for you on Monday. The easiest way to do this is the following:

                     

                    - map a network share

                    - deploy image (sysprep or automated install?)

                    - inject unattended.xml

                    - now you can run a autoit script or whatever you want from your network share to edit computername or ldap ou in your unattended.xml

                    - run Hii

                    - run CTOS

                    - reboot

                     

                     

                    With autoit you could really simple create wmi calls to save system serial in a given variable and then replace a dummy computername in your unattended.xml. It is also possible to auto generate your computername by increment.

                    • 7. Re: Script during Provisioning to return a Variable
                      Apprentice

                      Marcel,

                      If you can share a script it would be great.  This step is what I've been trying to find a solution for.

                       

                      "now you can run a autoit script or whatever you want from your network share to edit computername or ldap ou in your unattended.xml"

                       

                      I've got a script that passes the variable back to other imaging apps like Altiris or MDT, and another that modifies XML, but haven't been able to put the pieces together successfully.  I am not a programmer by any means...

                       

                      I'll also grab Autoit to see if I can figure it out and come up with a solution using it.

                       

                      Thanks again

                      • 8. Re: Script during Provisioning to return a Variable
                        marcel Specialist

                        Ok I will post my script next Monday. But if you want only serial number as computername it is easier to define a global var in provisioning and inject it direct in your unattended.xml ( http://community.landesk.com/support/thread/18702 )

                        1 of 1 people found this helpful
                        • 9. Re: Script during Provisioning to return a Variable
                          Apprentice

                          Thanks Marcel

                          None of these PCs will have been in LANDesk before, so the database does not have the serial to inject into the unattend.xml.

                           

                          We are imaging batches of systems 50+.  They are new in box, racked to image, on network just long enough to configure for the end-user and then shipped to remote users.

                          • 10. Re: Script during Provisioning to return a Variable
                            marcel Specialist

                            After the automated miniscan in startnet.bat the serial is there. Provisioning is based on clients serial as server identifier, so you can image only by serial as identifier too.

                            • 11. Re: Script during Provisioning to return a Variable
                              Apprentice

                              I'll take a look.  We are starting Provisioning fom the PC side, no Scheduled Task or PCs entered in LD.  I never saw one come up in LD when Provisioning, but that's not to say I just didn't see it.

                               

                              I'll start a new test in the AM and take a look at the DB.

                               

                              I've also got a script working that pulls from WMI and injects values in an XML file working locally on my PC.  If the DB doesn't contain what I need, I'll start looking at getting the script woking with the Provisioning process.

                               

                              I may just go with the script since it can also make some other adjustments to my unattend.xml.

                               

                              Thanks

                              • 12. Re: Script during Provisioning to return a Variable
                                Apprentice

                                Marcel - thanks for your assistance and pointing me down two paths, both of which work.

                                 

                                The PC being deployed still doesn't show up in my console when searching, but the article you reference still works.  So there is one way.

                                 

                                The script I put together using Autoit and _XMLDomWrapper is below if anyone wants to use it.  Pull it into the editor in this format with the _XMLDomWrapper.au3 and Array.au3 includes available and compile it into an exe.

                                 

                                This sample queries WMI for the serial number, creates the name "PC-xxxxxxx" and inserts the name into unattend.xml in the same folder as the script.  The script below modifies the ComputerName field, but it could be modifed to inject Product ID, OU for domain join, etc.

                                 

                                I didn't try for much logic or bug catching here - so if Serial is not in your BIOS, your unattend.xml is formatted differently or the unattend.xml isn't in the same folder, it will simply fail to work.  In other words - test thoroughly and use at your own risk.

                                ______________________________________________________________________________________________________

                                #include <_XMLDomWrapper_3.au3>

                                #include <Array.au3>

                                 

                                $sXML = @ScriptDir & "\unattend.xml"

                                $sXmlNS = '"urn:schemas-microsoft-com:unattend"'

                                $sXmlQuery = '/MyNS:unattend/MyNS:settings[@pass="specialize"]/MyNS:component[@name="Microsoft-Windows-Shell-Setup"]/MyNS:ComputerName'

                                 

                                $iRET = _XMLFileOpen($sXML)

                                 

                                $wbemFlagReturnImmediately = 0x10

                                $wbemFlagForwardOnly = 0x20

                                $colItems = ""

                                $strComputer = "localhost"

                                 

                                $Serial=""

                                $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")

                                $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_SystemEnclosure", "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly)

                                 

                                If IsObj($colItems) then

                                   For $objItem In $colItems

                                      $Serial = $objItem.SerialNumber

                                   Next

                                Else

                                   Msgbox(0,"WMI Results","No WMI Objects Found for class - unable to retrieve SerialNumber: "

                                & "Win32_SystemEnclosure" )

                                Endif

                                 

                                $compname = "PC-" & $Serial

                                 

                                $objDoc.setProperty("SelectionNamespaces", 'xmlns:MyNS=' & $sXmlNS)

                                 

                                _XMLUpdateField($sXmlQuery, $compname)

                                • 13. Re: Script during Provisioning to return a Variable
                                  joe.denice Apprentice

                                  So I am trying to do this for my image, right now we just user a generic name in the unattend.xml. Before we had a powershwell script change the PC name but I want to use this method instead if possible. Do I need to include the "#include" lines in this file? I guess I want to create it as an .xml file and then load it up as a script. Once that is done do I put that scrip in place after the unattend.xml files gets loaded onto the computer in the OSD?

                                  • 14. Re: Script during Provisioning to return a Variable
                                    Apprentice

                                    Sorry - I only used this method for a very short period of time, so I can't remember if I had it in my base image or copied it with the unattend.xml during provisioning.

                                     

                                    The script is AutoIt, so you need to compile it as such.  Yes you do need the #includes in the script and also need the au3 files referenced when you compile it as an exe.

                                     

                                    From my message above:

                                    The script I put together using Autoit and _XMLDomWrapper is below if anyone wants to use it.  Pull it into the editor in this format with the _XMLDomWrapper.au3 and Array.au3 includes available and compile it into an exe.


                                    Google "AutoIt" and you'll find a wealth of resources including some pretty decent support forums.

                                    1 2 Previous Next