在域用户下,需要退出域,自动运行此脚本,省去了麻烦。
1、开启脚本的执行权限。
Set-ExecutionPolicy Unrestricted
2、将密码输入,生成密文(一个坏习惯)
read-host -AsSecureString | convertfrom-securestring | out-file C:\passwd.txt
3、脚本中调用此参数
Domain = "abc.com" #Your domain
$username = "abc.com\spring-song-a" #Your domain admin username
$password = cat C:\passwd.txt | convertto-securestring
$cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $username, $password
remove-computer -credential $cred -passthru -verbose
Restart-Computer
4.系统会自动重启,完成退域工作。
Remove and automatically Re-add Computer from Domain using PowerShell scripts
====参考链接===
1、自动加域工具,支持xp_win7_win8_win10_小黑侠_新浪博客