VMware Cloud Community
spride
Enthusiast
Enthusiast

vRA 6.2: Powershell script in build profile not changing computer name

We have a Windows Server 2012R2 blueprint which contains a build profile that runs a Powershell script to change the computer name, but doesn't appear to be working correctly.  I put statements in the script to output information to a log file when it runs, and the log output shows the script is running, but it's just not changing the name of the computer and then rebooting like it is supposed to.  The last few lines of the script look like this:

$newName | Out-File c:\windows\temp\newname.log -append

Rename-Computer -NewName $newName -Force | Out-File c:\windows\temp\newname.log -append

Restart-Computer

The VM never actually restarts when this script is run at provision time, but if I run the script manually after the VM is up it runs fine (i.e., the name is changed and the computer restarts).

The build profile section looks like this ..

VirtualMachine.Admin.UseGuestAgent       true

VirtualMachine.Customize.Waitcomplete    true

VirtualMachine.Software0.Name            Rename Computer

VirtualMachine.Software0.ScriptPath      PowerShell -ExecutionPolicy Bypass "\\mywinutil\gugent\RenameComputer.ps1 -hostname {Hostname} -loc {LOC}"

Again, from the log output it shows the script runs, the parameters get passed in fine, there are no errors, etc. - just that the last two lines of the script act as though they never run at all.  Any ideas?  Thanks.

Reply
0 Kudos
3 Replies
Craig_G2
Hot Shot
Hot Shot

Hey,

I would personally use vCenter Customisation specifications to do this...  It's far less complicated... and also the GuestAgent can slow down windows builds quite a bit.


Unless of course you are setting the VM name differently to the name generated by the Machine prefix?

Cheers

Reply
0 Kudos
pizzle85
Expert
Expert

is there a reason you're not using the native "Hostname" property?

http://pubs.vmware.com/vCAC-60/topic/com.vmware.ICbase/PDF/vcloud-automation-center-60-custom-proper...

Using the "Hostname" property will name the machine in vRA, vCenter. I if you run it through a custom spec you can just use the vCenter name to name the machine in the OS.


For scripting i personally use the Guest script manager package: Guest script manager package

Reply
0 Kudos
Craig_G2
Hot Shot
Hot Shot

Yup - this is the way to do it if you want to allow people  to chose names and not use machine prefixes. 🙂

Reply
0 Kudos