powershell 如何实现电脑加域退域?


PowerShell交流中心分类: Powershell基础powershell 如何实现电脑加域退域?
0
匿名用户 asked 10年 ago

如何使用powershell实现客户端电脑加域或退域

1 Answers
0
Best Answer
Mooser Lee 管理员 answered 10年 ago

用add-computer和remove-computer命令。

#加域
Add-Computer -ComputerName Server01 -LocalCredential Server01\Admin01 -DomainName Domain02 -Credential Domain02\Admin02 -Restart -Force
#退域
Remove-Computer -UnjoinDomaincredential Domain01\Admin01 -Passthru -Verbose -Restart
scp420 replied 10年 ago

function JoinDomain{ $DomainName = [System.Net.NetworkInformation.IPGlobalProperties]::GetIPGlobalProperties().DomainName if ($DomainName.Length -gt 0) { $textbox1.AppendText(“此服务器已加入域,请先退域后再加入新域!`n”) break } elseif ($DomainName.Length -eq 0) { $domain = Read-Host “请输入你所要加入的AD域名:” Add-Computer -DomainName $domain }}function LevelDomain{ $DomainName = [System.Net.NetworkInformation.IPGlobalProperties]::GetIPGlobalProperties().DomainName if ($DomainName -is [string]) { $textbox1.AppendText(“此服务器即将退出域,请确认!`n”) $inputY2N = Read-Host “请输入Yes or No!” if ($inputY2N -eq ‘yes’) { $DomainUserAdmin = Read-Host “请输入域管理员帐号” remove-computer -credential $DomainUserAdmin -passthru -verbose $textbox1.AppendText(“此服务器已退出域”) Restart-Computer -ComputerName . } elseif ($inputY2N -eq ‘no’) { return } }}