#获取用户名,重命名pc
$Username = Read-Host "Please enter your Username:" -ErrorAction Stop
$PcName = $Username+"-pc1"
Rename-Computer -NewName $PcName -Force
#加域
$User = "poweruser"
$Password = "IT@user666" | ConvertTo-SecureString -asPlainText -Force
$credential = New-Object System.Management.Automation.PSCredential($User,$Password)
#以新pc名加入到域
Add-Computer –NewName $PcName -DomainName lexinfintech.com -Confirm:$false -Credential $credential |Out-File -FilePath c:\joindomain.log
#添加删除用户组成员
$Domainuser = "lexinfintech\"+$Username
Add-LocalGroupMember -Group users -Member $Domainuser |Out-File -FilePath c:\joindomain.log -Append
Remove-LocalGroupMember -Group users -Member “LEXINFINTECH\Domain Users”|Out-File -FilePath c:\joindomain.log -Append
Add-LocalGroupMember -Group "Remote Desktop Users" -Member $Domainuser |Out-File -FilePath c:\joindomain.log -Append
#添加权限
icacls C:\windows\System32\drivers\etc\hosts /grant Users:F |Out-File -FilePath c:\joindomain.log -Append
#重启电脑
Restart-Computer