备注:
将域控账号保存到脚本中,减少手指的工作量(这个是运维的基本素质)!!!!
$UserName = "域控管理员账号@XXXX.com"
$PassWord = ConvertTo-SecureString -String "域控管理员密码" -AsPlainText -Force
`$Credential = New-Object -TypeName "System.Management.Automation.PSCredential" -ArgumentList $UserName,$PassWord
`
远程控制
Invoke-Command -ComputerName 远程计算机名 -ScriptBlock{
$UserName = "域控管理员账号@XXXX.com"
$PassWord = ConvertTo-SecureString -String "域控管理员账号" -AsPlainText -Force
`$Credential = New-Object -TypeName "System.Management.Automation.PSCredential" -ArgumentList $UserName,$PassWord
`
修改命令在下方(这个命令可以随意修改成你喜欢的例如开放端口或者关闭增加权限)
Rename-Computer -NewName 计算机新名称 -DomainCredential $Credential
Add-LocalGroupMember -Group "组名称" -Member 域控/成员
} -Credential $Credential