Fail to apply VM Customization Specifications: Command to Run Once are not executed upon VM deployment.
search cancel

Fail to apply VM Customization Specifications: Command to Run Once are not executed upon VM deployment.

book

Article ID: 314677

calendar_today

Updated On:

Products

VMware vSphere ESXi

Issue/Introduction

  • This article provides information and best practises on applying a command to run once on a VM upon its deployment. 
  • This KB goes over typical checks that can be done for troubleshooting similar issues from both the vCenter and Windows GUEST OS side.



Symptoms:

  • Writing a command to run once after deploying a VM in the VM customization Specifications as below, doesn't work:
  • In the "C:\WINDOWS\TEMP\customize-guest. log" file: We can see the below lines indicating the logging of the command.
  • From the : guestcust.log
    [YYYY-MM-DDTHH:MM:SS:     WindowsOsAbstractionLayer:   WARN] Command execution failed with exit code: 1060, output: '[SC] EnumQueryServicesStatus:OpenService FAILED 1060:
    
    The specified service does not exist as an installed service.
    
    
    [YYYY-MM-DDTHH:MM:SS:                 GuestCustUtil:  DEBUG] SchedulePostCustomizationActivity: Run Command-'HandleCustomizationCompleted<\|/>'
    [YYYY-MM-DDTHH:MM:SS:                 GuestCustUtil:   INFO] Scheduling post-customization activity to run after reboot...
    [YYYY-MM-DDTHH:MM:SS:     WindowsOsAbstractionLayer:   INFO] Executing command: 'C:\Windows\system32\sc.exe query "VMware Guest OS Customization Task" '
    [YYYY-MM-DDTHH:MM:SS:     WindowsOsAbstractionLayer:   WARN] Command execution failed with exit code: 1060, output: '[SC] EnumQueryServicesStatus:OpenService FAILED 1060:
    
    The specified service does not exist as an installed service.
    As an indicator to a wrong syntax for the applied command and hence, the command is not executed on start upon VM deployment.
  • Upon changing the command to a simpler one: mkdir: C:\Temp\test as below:
  • The customization task succeeded, and no errors in guestcust.log as per the logs below:
    MMM DD HH:MM:SS VM vpxd[6359]: Event [-1973926310] [1-1] [YYYY-MM-DDTHH:MM:SS.784808Z] [vim.event.CustomizationStartedEvent] [info] [User] [CSI DataCenter 01] [-1973926310] [Started customization of VM. Customization log located at C:/Windows/TEMP/vmware-imc/guestcust.log in the guest OS.]
    
    
    MMM DD HH:MM:SS VM vpxd[6359]: Event [-1973925463] [1-1] [YYYY-MM-DDTHH:MM:SS.227665Z] [vim.event.CustomizationSucceeded] [info] [User] [CSI DataCenter 01] [-1973925463] [Customization of VM succeeded. Customization log located at C:/Windows/TEMP/vmware-imc/guestcust.log in the guest OS.]
  • However, the command is still not executed.
  • Note: The above log excerpts are only examples. Date, time, and environmental variables may vary depending on your environment.



Cause

This is because of: Issues in the syntax and format of the command/script.

Resolution

In order to write an executable command to run once upon a VM creation, the following parameters need to be taken into consideration:

  1. Format: The written command/script format needs to have the full binary path and the parameters in the command. ie: We can't use "mkdir c:\temp\test" in FirstLogonCommands but instead it should be: "C:\Windows\System32\cmd.exe /c mkdir C:\Temp\test"
  2. Syntax: The syntax of the written command/scripts need to follow Microsoft CommandLine Guidelines. Usually, The VMware GUEST OS customization copies the commands in the customer's specification into a Windows OS unattended file and launches sysprep.exe to implement the unattended file in Windows OS customization. According to https://learn.microsoft.com/en-us/windows-hardware/customize/desktop/unattend/microsoft-windows-shell-setup-firstlogoncommands-synchronouscommand-commandline Even though the Path_to_command is a string with a maximum length of 1024 characters, the actual sysprep triggers the commands through run-and-runonce-regeistry-keys. https://learn.microsoft.com/en-us/windows/win32/setupapi/run-and-runonce-registry-keys
    The above document says "The data value for a key is a command line no longer than 260 characters."
  3. Hence, any command we use will only be executed if the command length was less than 260.



Additional Information

Impact/Risks:
  • The written script/command to run upon start in a VM is not executed properly.