5 Replies Latest reply on Mar 18, 2010 2:56 AM by a4ivmware

    Create OSCustomization based on Custom Sysprep file

    a4ivmware Novice

      Hello,

       

      As I said in my previous thread (http://communities.vmware.com/thread/258509), there is no cmdlet to create an OSCustomization based on Custom Sysprep File.

       

      So, I need to create a PowerShell script using the .Net API to perform this task.

       

      Unfortunately, I'm not a .Net guru and there are few information about how to use the createcustomizationspec() method.

       

       

       

       

       

       

      Actually, I'm receiving the following error when I run my script :

       

      Exception calling "CreateCustomizationSpec" with "1" argument(s): "Not initialized: string type" At :line:37 char:29 ++ $view.CreateCustomizationSpec <<<< ($vmcloneitem)+

       

       

       

       

       

       

      If someone have an idea to solve this problem...

       

       

       

       

       

       

      Here is mys script:

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

      1. Test Script to create Customization

      $vc_user="username"

      $vc_password="password"

      $codeuc = 500

      $codeip = 221

      $codevc = ""

      $nom_custo = "testcusto"

      $datastore = "PROD_1_1"

       

      $SysPrep = "`";SetupMgrTag InstallFilesPath=C:\install OemPreinstall=Yes FileSystem = ConvertNTFS ExtendOEMPartition = 0 TargetPath = \WINNT OemSkipEula = yes LegacyNIC = 1 UnattendMode=FullUnattended UnattendSwitch=Yes WaitForReboot=Yes AdminPassword=`"password`" EncryptedAdminPassword=NO OEMSkipRegional=1 TimeZone=105 OemSkipWelcome=1 Autologon=yes AutologonCount=5 ServerWelcome=No ComputerName = GENERIQUE ProductKey=XXXXX-YYYYY-TTTTT-DDDDD-EEEEE FullName=`"ORG`" OrgName=`"ORG`" BitsPerPel=16 Xresolution=1024 YResolution=768 VRefresh=60 AutoMode=PerSeat BrandIEUsingUnattended=No IEBrandingFile=Install.ins Proxy_Enable=1 Use_Same_Proxy=1 FTP_Proxy_Server=http://proxy:80 Gopher_Proxy_Server=http://proxy:80 HTTP_Proxy_Server=http://proxy:80 accessopt = Off aspnet = Off cdplayer = Off cluster = Off deskpaper = Off dialer = Off fp_extensions = Off freecell = Off iis_asp = Off iis_common = Off iisdbg = Off iis_doc = Off iis_ftp = Off iis_htmla = Off iis_inetmgr = Off iis_nntp = Off iis_nntp_docs = Off iis_pwmgr = Off iis_www = Off iis_smtp = Off iis_smtp_docs = Off LicenseServer = Off media_clips = Off minesweeper = Off mousepoint = Off mplay = Off paint = Off pinball = Off rec = Off reminst = Off solitaire = Off templates = Off TerminalServer = Off TSClients = Off TSEnable = Off vol = Off WMS = Off WMS_Admin = Off WMS_SERVER = Off AllowConnections = 1 LicensingMode = PerDevice PermissionsSetting = 1 DefaultStartPanelOff=YES DefaultThemesOff=YES JoinWorkgroup=WORKGROUP Networking Adapter01 = params.Adapter01 Adapter02 = params.Adapter02 http://params.Adapter01 PCIBusNumber = 0 PCIDeviceNumber = 17 PCIFunctionNumber = 0 ConnectionName = `"Public`" http://params.Adapter02 PCIBusNumber = 0 PCIDeviceNumber = 18 PCIFunctionNumber = 0 ConnectionName = `"Backup`" MS_MSClient = params.MS_MSClient http://params.MS_MSClient MS_TCPIP = params.MS_TCPIP http://params.MS_TCPIP AdapterSections = params.MS_TCPIP.Adapter01,params.MS_TCPIP.Adapter02 http://params.MS_TCPIP.Adapter01 Ipaddress=192.168.38.20 Subnetmask=255.255.224.0 DefaultGateway=192.168.32.1 SpecificTo = Adapter01 Dhcp=no http://params.MS_TCPIP.Adapter02 Ipaddress=192.168.65.20 Subnetmask=255.255.255.0 SpecificTo = Adapter02 Dhcp=no MS_Server = params.MS_Server http://params.MS_Server BroadcastsToLanman2Clients = No Optimization = Balance DNS = 0 DHCPServer = 0 LPDSVC = 0 SNMP = 1 WINS = 0 RA_AllowToGetHelp = 1 Community_Name = Public Traps=snmpmesm.fr.auchan.com Accept_CommunityName = Public:Read_Write Send_Authentication = Yes Command01 = `"CMD /c c:\sources\vmware\hal\Proc-hal.cmd 1`" Command02 = `"CMD /q /c c:\sources\vmware\dskpart.cmd`" Command03 = `"cscript c:\sources\Launch_MESM_Master.vbs $codeip $codeuc 18`" Command04 = `"netset03 c:\sources\network.inf`" Command05 = `"CMD /C d:\winnt\system32\cscript.exe c:\master\scripts\1_start.vbs %computername% administrator factor socle.txt`"`""

       

      Connect-VIServer -Server $codevc -User $vc_user -Password $vc_password

       

      #New Customization

      $vmcloneitem = New-Object VMware.Vim.CustomizationSpecItem

       

      #Infos de la Customization

      $vmcloneinfo = New-Object VMware.Vim.CustomizationSpecInfo

      $vmcloneinfo.Name = "testcusto"

      $vmcloneinfo.Description = "VM100TEST"

      $vmcloneitem.Info = $vmcloneinfo

       

      #spécification de la Customization

      $vmclonespec = New-Object VMware.Vim.CustomizationSpec

      $vmclonespec.Identity = New-Object VMware.Vim.CustomizationSysprepText

      $vmclonespec.Identity.Value = $SysPrep

      $vmclonespec.Options = New-Object VMware.Vim.CustomizationWinOptions

      $vmclonespec.Options.changeSID = 1

      $vmclonespec.Options.DeleteAccounts = 0

      $vmcloneitem.Spec = $vmclonespec

       

      $view = get-view CustomizationSpecManager

      $view.CreateCustomizationSpec($vmcloneitem)

        • 1. Re: Create OSCustomization based on Custom Sysprep file
          golddiggie Virtuoso

          I fail to see why the Customization settings/wizard doesn't do the job for you. I've had great results with it, especially under ESXi4. You can give it plenty of parameters, as well as have it take input for things like the VM's name and name to be used when joining to the domain. If you need to perform additional tweaking of the VM's during deployment, what about using batch files, referenced in the template, to do the job?

          • 2. Re: Create OSCustomization based on Custom Sysprep file
            LucD Guru
            vExpertCommunity WarriorsUser Moderators

            There were only 2 lines missing.

            Below your script with the extra lines (I marked them with the comment "# added").

             

            When you are constructing these objects the SDK Reference tells you what needs to be there and what can be $null.

            For example, the type property in the CustomizationSpecInfo object is not marked with a red asterisk. That means the property can not be $null.

             

            Same for the globalIPSettings property in the CustomizationSpec object. Note that with this last property, only the object needs to be there, the properties inside the object can stay $null.

             

            $vc_user="username"
            $vc_password="password"
            $codeuc = 500
            $codeip = 221
            $codevc = ""
            $nom_custo = "testcusto"
            $datastore = "PROD_1_1"
            
            $SysPrep = "`";SetupMgrTag Unattended InstallFilesPath=C:\install OemPreinstall=Yes FileSystem = ConvertNTFS ExtendOEMPartition = 0 TargetPath = \WINNT OemSkipEula = yes LegacyNIC = 1 UnattendMode=FullUnattended UnattendSwitch=Yes WaitForReboot=Yes GuiUnattended AdminPassword=`"password`" EncryptedAdminPassword=NO OEMSkipRegional=1 TimeZone=105 OemSkipWelcome=1 Autologon=yes AutologonCount=5 ServerWelcome=No UserData ComputerName = GENERIQUE ProductKey=XXXXX-YYYYY-TTTTT-DDDDD-EEEEE FullName=`"ORG`" OrgName=`"ORG`" Display BitsPerPel=16 Xresolution=1024 YResolution=768 VRefresh=60 LicenseFilePrintData AutoMode=PerSeat Branding BrandIEUsingUnattended=No IEBrandingFile=Install.ins Proxy Proxy_Enable=1 Use_Same_Proxy=1 FTP_Proxy_Server=http://proxy:80 Gopher_Proxy_Server=http://proxy:80 HTTP_Proxy_Server=http://proxy:80 Components accessopt = Off aspnet = Off cdplayer = Off cluster = Off deskpaper = Off dialer = Off fp_extensions = Off freecell = Off iis_asp = Off iis_common = Off iisdbg = Off iis_doc = Off iis_ftp = Off iis_htmla = Off iis_inetmgr = Off iis_nntp = Off iis_nntp_docs = Off iis_pwmgr = Off iis_www = Off iis_smtp = Off iis_smtp_docs = Off LicenseServer = Off media_clips = Off minesweeper = Off mousepoint = Off mplay = Off paint = Off pinball = Off rec = Off reminst = Off solitaire = Off templates = Off TerminalServer = Off TSClients = Off TSEnable = Off vol = Off WMS = Off WMS_Admin = Off WMS_SERVER = Off TerminalServices AllowConnections = 1 LicensingMode = PerDevice PermissionsSetting = 1 Shell DefaultStartPanelOff=YES DefaultThemesOff=YES Identification JoinWorkgroup=WORKGROUP Networking NetAdapters Adapter01 = params.Adapter01 Adapter02 = params.Adapter02 http://params.Adapter01 PCIBusNumber = 0 PCIDeviceNumber = 17 PCIFunctionNumber = 0 ConnectionName = `"Public`" http://params.Adapter02 PCIBusNumber = 0 PCIDeviceNumber = 18 PCIFunctionNumber = 0 ConnectionName = `"Backup`" NetClients MS_MSClient = params.MS_MSClient http://params.MS_MSClient NetProtocols MS_TCPIP = params.MS_TCPIP http://params.MS_TCPIP AdapterSections = params.MS_TCPIP.Adapter01,params.MS_TCPIP.Adapter02 http://params.MS_TCPIP.Adapter01 Ipaddress=192.168.38.20 Subnetmask=255.255.224.0 DefaultGateway=192.168.32.1 SpecificTo = Adapter01 Dhcp=no http://params.MS_TCPIP.Adapter02 Ipaddress=192.168.65.20 Subnetmask=255.255.255.0 SpecificTo = Adapter02 Dhcp=no NetServices MS_Server = params.MS_Server http://params.MS_Server BroadcastsToLanman2Clients = No Optimization = Balance NetOptionalComponents DNS = 0 DHCPServer = 0 LPDSVC = 0 SNMP = 1 WINS = 0 PCHealth RA_AllowToGetHelp = 1 SNMP Community_Name = Public Traps=snmpmesm.fr.auchan.com Accept_CommunityName = Public:Read_Write Send_Authentication = Yes GuiRunOnce Command01 = `"CMD /c c:\sources\vmware\hal\Proc-hal.cmd 1`" Command02 = `"CMD /q /c c:\sources\vmware\dskpart.cmd`" Command03 = `"cscript c:\sources\Launch_MESM_Master.vbs $codeip $codeuc 18`" Command04 = `"netset03 c:\sources\network.inf`" Command05 = `"CMD /C d:\winnt\system32\cscript.exe c:\master\scripts\1_start.vbs %computername% administrator factor socle.txt`"`""
            
            # Connect-VIServer -Server $codevc -User $vc_user -Password $vc_password
            
            #New Customization
            $vmcloneitem = New-Object VMware.Vim.CustomizationSpecItem
            
            #Infos de la Customization
            $vmcloneinfo = New-Object VMware.Vim.CustomizationSpecInfo
            $vmcloneinfo.Name = "testcusto"
            $vmcloneinfo.Description = "VM100TEST"
            $vmcloneitem.Info = $vmcloneinfo
            $vmcloneinfo.Type = "Windows"          # added
            
            #spécification de la Customization
            $vmclonespec = New-Object VMware.Vim.CustomizationSpec
            $vmclonespec.Identity = New-Object VMware.Vim.CustomizationSysprepText
            $vmclonespec.Identity.Value = $SysPrep
            $vmclonespec.Options = New-Object VMware.Vim.CustomizationWinOptions
            $vmclonespec.Options.changeSID = 1
            $vmclonespec.Options.DeleteAccounts = 0
            $vmcloneitem.Spec = $vmclonespec
            $vmclonespec.GlobalIPSettings = New-Object VMware.Vim.CustomizationGlobalIPSettings              # added
            
            
            $view = get-view CustomizationSpecManager
            $view.CreateCustomizationSpec($vmcloneitem) 
            

            Note that this is not necessarily a workin customisation specificiation.

            It's just passes the checks the CreateCustomizationSpec method does.

             

             

             

            ____________

            Blog: LucD notes

            Twitter: lucd22

            • 3. Re: Create OSCustomization based on Custom Sysprep file
              avlieshout Expert
              VMware Employees

              Your sysprep looks invalid as some section names aren't enclosed in []

              Instead of putting all sysprep info into a string in the script use the get-content cmdlet to read the sysprep.inf file.

               

              $SysPrep = Get-Content <path>\<sysprep.inf>

               

              -


              Arnim van Lieshout

               

              Blogging: http://www.van-lieshout.com

              Twitter: http://www.twitter.com/avlieshout

               

              If you find this information useful, please award points for "correct" or "helpful".

              1 person found this helpful
              • 4. Re: Create OSCustomization based on Custom Sysprep file
                a4ivmware Novice

                In fact, I need to use a script to create the OSCustomization 'cause I'm using variables.

                • 5. Re: Create OSCustomization based on Custom Sysprep file
                  a4ivmware Novice

                   

                  Arnim,

                   

                   

                  Even when I'm using "Get-Content", the sysprep is not well formatted in the OSCustomization...

                   

                   

                  I'm currently looking for a solution...

                   

                   

                  Thanks for your help,

                   

                   

                  Dom