Dmitry Porotnikov / Powershell: Join VM to the Domain

Created Tue, 22 Aug 2023 13:12:58 +0000 Modified Tue, 22 Aug 2023 13:12:58 +0000
58 Words

Powershell: Join VM to the Domain

## Description: This script will join a computer to a domain and force a reboot
$domain = "lab.local"
$username = "$domain\username" 
$password = Read-Host 'What is your password?' -AsSecureString
$credential = New-Object System.Management.Automation.PSCredential($username,$password)
Add-Computer -DomainName $domain -Credential $credential
Write-Host ("Computer joined domain " + $domain)
gpupdate /force
shutdown -r -f -t 60