To join a Windows computer to a domain using PowerShell use the following script. You can read my previous post, here on how to create the password file.
#set domain, credential, and hostname variables $File = "C:\Scripts\Password.txt" $Key = (1..32) $UserName = "contoso.com\adjoin" $Password = Get-Content $File | ConvertTo-SecureString -Key $Key $DomainJoinCredentials = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $UserName,$Password $Domain = "contoso.com" $OU = "OU=ContosoComputers,DC=contoso,DC=com" #Join computer to domain Add-Computer -DomainName $Domain -Credential $DomainJoinCredentials -OUPath $OU
Leave a Reply