Customisation of newly created VM - GuiRunOnce

Hi I'm trying to customise newly deploye VM's but can't get the GuiRunOnce cmd to run. the command i'm specifying doesn't seem to run.

I generated a new customization script using Onyx which is bellow.

If I run the command specified in runonce in a VM manually exactly as its specified in GuiRunOnce it runs ok and i get the success message logged to the log file, so I know the command / permissions are good.

If I change the command in GuiRunOnce to something simple like "cmd /c echo > c:\test.txt", it also runs ok, so I know the customizationspec is good.

can anyone shed any light?

(the reaon i'm having to the spec the old way is due to me having to run PowerCli two versions old due to this issue:)


here's my customisation script as mentioned earlier created using Onyx.

has anyone got a working example of a customizationspec running netdom to join doman this way?

Connect-VIServer vcenter
# ------- CreateCustomizationSpec -------

$spec = New-Object VMware.Vim.CustomizationSpec
$spec.options = New-Object VMware.Vim.CustomizationWinOptions
$specoptions.changeSID = $true
$spec.options.deleteAccounts = $false
$spec.identity = New-Object VMware.Vim.CustomizationSysprep
$spec.identity.guiUnattended = New-Object VMware.Vim.CustomizationGuiUnattended
$spec.identity.guiUnattended.password = New-Object VMware.Vim.CustomizationPassword
$spec.identity.guiUnattended.password.value = "password"
$spec.identity.guiUnattended.password.plainText = $true
$spec.identity.guiUnattended.timeZone = 85
$spec.identity.guiUnattended.autoLogon = $true
$spec.identity.guiUnattended.autoLogonCount = 1
$spec.identity.userData = New-Object VMware.Vim.CustomizationUserData
$spec.identity.userData.fullName = "Corporate Data Centre"
$spec.identity.userData.orgName = "London Borough of Camden"
$spec.identity.userData.computerName = New-Object VMware.Vim.CustomizationVirtualMachineName
$spec.identity.userData.productId = "xxxxx-xxxxx-xxxxx-xxxxx-xxxxx"
$spec.identity.guiRunOnce = New-Object VMware.Vim.CustomizationGuiRunOnce*
$spec.identity.guiRunOnce.commandList = New-Object System.String[] (1)*
$spec.identity.guiRunOnce.commandList[0] = "c:\windows\system32\netdom join %computername% /d:lbcamden.net /ou:ou=Servers,ou=Managed,dc=test,dc=net /ud:test\joindomain /pd:password /reboot > c:\windows\temp\netdom.log"
$spec.identity.identification = New-Object VMware.Vim.CustomizationIdentification
$spec.identity.identification.joinWorkgroup = "WORKGROUP"
$spec.identity.licenseFilePrintData = New-Object VMware.Vim.CustomizationLicenseFilePrintData
$spec.identity.licenseFilePrintData.autoMode = "perSeat"
$spec.globalIPSettings = New-Object VMware.Vim.CustomizationGlobalIPSettings
$spec.globalIPSettings.dnsSuffixList = New-Object System.String[] (1)
$spec.globalIPSettings.dnsSuffixList[0] = "test.net"
$spec.nicSettingMap = New-Object VMware.Vim.CustomizationAdapterMapping[] (1)
$spec.nicSettingMap[0] = New-Object VMware.Vim.CustomizationAdapterMapping
$spec.nicSettingMap[0].adapter = New-Object VMware.Vim.CustomizationIPSettings
$spec.nicSettingMap[0].adapter.ip = New-Object VMware.Vim.CustomizationFixedIp
$spec.nicSettingMap[0].adapter.ip.ipAddress = ""
$spec.nicSettingMap[0].adapter.subnetMask = ""
$spec.nicSettingMap[http://0].adapter.gateway = New-Object System.String[http://0].adapter.gateway = New-Object System.String[] (2)
$spec.nicSettingMap[0].adapter.gateway[0] = ""
$spec.nicSettingMap[http://0].adapter.dnsServerList = New-Object System.String[http://0].adapter.dnsServerList = New-Object System.String[] (2)
$spec.nicSettingMap[0].adapter.dnsServerList[0] = ""
$spec.nicSettingMap[0].adapter.dnsServerList[1] = ""
$spec.nicSettingMap[0].adapter.primaryWINS = ""
$spec.nicSettingMap[0].adapter.secondaryWINS = ""

$vmname = Get-VM testvm
$vmv = Get-View $vmname.Id

Start-VM $vmname

0 Kudos
3 Replies
VMware Employee
VMware Employee


Onyx vs PowerCLI

Onyx is a great tool for generating .Net Toolkit scripts that do something that PowerCLI cmdlets can't. In this case you can convert your script to 3 single lines of PowerCLI script:

$spec = New-OSCustomizationSpec ....

Set-VM -VM testvm -OSCustomizationSpec $spec

Start-VM testvm

Using customization for joining domain

You can try using customization spec integrated functionality to join domain:

New-OSCustomzationSpec -Domain -DomainUser -DomainPassword

GuiRunOnce workaround

I'm not sure what exactly goes wrong with the GuiRunOnce command but you can do the following steps to avoid it:

1. Do the customization with customization specs and skip the GuiRunOnce parameter

2. Power on the VM

3. Use the Invoke-VMScript to run the netdom command on the guest VM

I hope this will help.


Nedko Nedev

PowerCLI Development Team

Regards, Nedko Nedev PowerCLI Development Team

whats the correct way to secure invoke-vmscript i.e. not leaving host and guest credentials in scripts? Also preferably without prompting the user to enter credentials either.

0 Kudos
VMware Employee
VMware Employee


The best way to secure passwords in script that I know is to use PowerShell secure strings. You can find very good explanation how to that here: http://vcommunity.vizioncore.com/administration/vecoshell/b/weblog/archive/2010/03/01/securing-crede...

I hope this will help.


Nedko Nedev

PowerCLI Development Team

Regards, Nedko Nedev PowerCLI Development Team
0 Kudos