I am using PowerCLI to create a large number of Mac VM's that will be using DHCP, and I am wanting to use the Invoke-VMScript command to set the hostname during VM creation. The issue is that when using the Invoke-VMScript command either in a scripted task, or by invoking the command directly, I repeatedly get a failed to authenticate error. This is happening with vCenter 6.5 on a macOS 10.10.5 VM using VMware Tools 10.0.12-Legacy, which is the most current version for 10.10 to my knowledge. Below is the script that I am using with the unique information edited for privacy. Any help would be greatly appreciated.
Code
$template = Get-Template -Name Mac_OS_10.10_v1.0.0
$datastore = Get-Datastore -Name "VM_Datastore_01"
$vapp = Get-VApp -Name “macOS-VM"
For ($i=01; $i -lt 10; $i++) {
$vm = New-VM -Name "vm0$i-macos" -VApp $vapp -Datastore $datastore -template $template
Start-Sleep -s 5
$vm | get-networkadapter | set-networkadapter -NetworkName "Private VLAN" -Confirm:$false
Start-Sleep -s 5
Set-VM $vm -NumCpu 6 -MemoryGB 64 -Confirm:$false
Do {
Start-Sleep -s 60
Start-VM $vm
$vm = Get-VM -Name "vm0$i-macos"
}
Until ($vm.PowerState -eq "PoweredOn")
Start-Sleep -s 60
Invoke-VMScript -VM $vm -ScriptText "sudo scutil --set HostName vm0$i-macos.domain.com" -GuestUser provision -GuestPassword 'password'
Invoke-VMScript -VM $vm -ScriptText "sudo scutil --set ComputerName vm0$i-macos.domain.com" -GuestUser provision -GuestPassword 'password'
Invoke-VMScript -VM $vm -ScriptText "dscacheutil -flushcache" -GuestUser provision -GuestPassword 'password'
Shutdown-VMGuest $vm -Confirm:$false
}
Error (Credentials are accurate from using to login to VM as well as SSH. Multiple credentials were attempted including root.)