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.