win_join_ad.ps1

$HostName = Read-Host 'Please input HostName'
Write-Host 'HostName: ' $HostName
$Domain = 'Yudelei.com'
$TUser1 = 'Administrator'
Write-Host 'Local admin user number list: '
Write-Host '    1: administrator'
Write-Host '    2: other '
$TUserNumber = Read-Host 'Please input the local admin user number'
if ($TUserNumber -eq '1')
    { $TUser = $TUser1 }
else 
    { $TUser = Read-Host 'Please input local admin user name'}
Write-Host 'Local admin: '$TUser
Write-Host 'Set local admin password.'
$Password = ConvertTo-SecureString -String "P@ssw0rd" -AsPlainText -Force
Set-LocalUser -Name $TUser -Password $Password
#Write-Host 'Set HostName.'
#Rename-Computer $HostName
$Credential = Get-Credential
if ($Credential){
    try{Add-Computer -DomainName $Domain -NewName $HostName -Credential $Credential -Restart -Force}
    catch{ 
        Write-Host 'Remove PC in AD. '
        Remove-Computer -UnjoinDomainCredential $Credential -PassThru -Verbose -Restart
    }
}
else
    {Write-Host 'No things to do. End.'}
最后修改:2021 年 07 月 08 日 06 : 26 PM
如果觉得文章帮助了您,您可以随意赞赏。