Trying to rejoin a machine to the domain. But I am only seeing one reboot on this. I think the script jumps directly from
Invoke-VMScript -vm $vm -GuestCredential $localcredential -ScriptType bat -ScriptText "netdom remove %computername% /domain:$domain /userd:$domainusername /passwordd:xxxxxx /reboot" -Verbose -RunAsync
to
Invoke-VMScript -vm $vm -GuestCredential $localcredential -ScriptType bat -ScriptText "netdom join %computername% /domain:$domain /userd:$domainusername /passwordd:yyyyyyy /reboot" -Verbose -RunAsync
and skips the first reboot. any idea?
$domain = "domain.com"
$domainusername = "administrator@$domain"
$domainpassword = "xxxxxx" | ConvertTo-SecureString -asPlainText -Force
$domcredential = New-Object System.Management.Automation.PSCredential($domainusername,$domainpassword)
$localadmin = "$computer\administrator"
$localadminpassword = "yyyyyyy" | ConvertTo-SecureString -AsPlainText -Force
$localcredential = New-Object System.Management.Automation.PSCredential($localadmin,$localadminpassword)
$vms = get-vm -name (get-content "c:\scripts\vms.txt")
ForEach ($vm in $vms) {
Invoke-VMScript -vm $vm -GuestCredential $localcredential -ScriptType bat -ScriptText "netdom remove %computername% /domain:$domain /userd:$domainusername /passwordd:xxxxxx /reboot" -Verbose -RunAsync
sleep 30
Wait-Tools -VM $vm
write-host "rejoining $vm to the domain"
Invoke-VMScript -vm $vm -GuestCredential $localcredential -ScriptType bat -ScriptText "netdom join %computername% /domain:$domain /userd:$domainusername /passwordd:yyyyyyy /reboot" -Verbose -RunAsync
}
I'm not a netdom specialist, did you already try with PowerShell (if available).
Remove-Computer -Credential domain1\admin -PassThru -Verbose
Restart-Computer -Confirm:$false
And for the join
Add-Computer -DomainName domain1 –credential domain1\admin -Restart -Force
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
when i use remove-computer its hanging
invoke-vmscript -vm server -guestcredential $localcrdential -scripttype bat "dir c:\" - works
invoke-vmscript -vm server -guestcredential $localcredential -scripttype powershell "get-service" works
but
invoke-vmscript -vm server -guestcredential $localcredential -scripttype bat "remove-computer -credential $localcredential -passthru -verbose"
is hanging
Did you also try the Remove-Computer remotely by using the ComputerName parameter and running the cmdlet from your station?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
yes no problem running it locally
remove-computer -computername servername -credential $domaincreds -passthru -force -restart
Could it be that the Remove-Computer via Invoke-VMScript hangs due to a (confirmation) prompt?
Perhaps try adding the -Confirm:$false switch.
If that doesn't fix the issue perhaps use Start-Transcript/Stop-Transcript or redirect the output of the cmdlet to a file.
Perhaps that shows what causes the hang.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
This "Operation is not allowed in the current state" is strange.
What does this show?
(Get-VM -Name <VMname>).ExtensionData.Guest
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
thanks
The VMware Tools are running and ready to accept commands.
Are you still getting that state error when you run a simple command via Invoke-VMScript.
Perhaps try 1st with a simple dir or Get-Service
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
iu rebooted and its completed hung now
i am able to run get-service and dir c:
Are you sure UAC is not enabled in the guest OS on that VM?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
uac is off
And are you seeing the same for all VMs that you try to leave/join the domain?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference