Hi Luc,
I did a workaround with the the netdom command, this works better, I don know the thing with @´ is not working at all
first question. I need to do a password trick to get it back in plaintext, otherwise the invoke command has problems to get the password
$DomainAccountPWD = Get-Credential $userID | ConvertTo-SecureString -asPlainText -force is not working, $DomainAccountPWD will not be correct transferd in the invoke command. Is there a better way to do it? or i use the plaintext trick
second question
reboot and wait-tools is not working reliable, mostly the script is running over.. whats wrong?
thanks
#######################################
#
cls
$userid = whoami
#$DomainAccountPWD = Get-Credential $userID | ConvertTo-SecureString -asPlainText -force ### not working
$domain = 'mydomain'
Param(
$DomainAccountPWD = (Read-Host "Dein Domain Admin Password für den Join" -AsSecureString)
)
Write-Host "Encrypted Password: $(ConvertFrom-SecureString $DomainAccountPWD)"
$ADpass = [Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR($DomainAccountPWD))
#VM Inventory names to match
$matchVMs = "VMTEST01"
#Guest Credentials - Must have required permissions to change IP address
$GuestUserName = "Administrator"
$GuestPassword = "localpassword!"
##############NO CHANGES BEYOND THIS POINT##############
#List of VMs (vCenter Inventory Names) to change
Write-Host "Getting list of VMs from Inventory where Inventory Name contains $matchVMs"
$VM = (get-vm | where {$_.Name -match $matchVMs -and $_.PowerState -eq "PoweredOn"}).Name
$netdom = "netdom join $vm /domain:$domain /userd:$userID /passwordd:$ADpass"
Invoke-VMScript -vm $vm -scriptType bat -ScriptText $netdom -GuestUser $GuestUserName -GuestPassword $GuestPassword
##reboot and wait until vm is back
Restart-VMguest -VM $VM -Confirm:$false | out-null
sleep -Seconds 5
write-host $vm "VM is rebooting"
Wait-Tools -VM $vm
write-host $vm "VM is online again"
$VMs
write-host " VM Domain Join done"