benmo | 发布于 2018-03-15 14:03:48 | 阅读量 748 | ? PowerShell ? ? AD ?
发布于 2018-03-15 14:03:48 | ? PowerShell ? ? AD ?

加域脚本:

$domain = "域"
$username = "有权限的域账户名"
$password = "域账户的密码" | ConvertTo-SecureString -asPlainText -Force
 
function JoinDomain 
{
    $computer = $env:COMPUTERNAME
	$DomainName = [System.Net.NetworkInformation.IPGlobalProperties]::GetIPGlobalProperties().DomainName
	if ($DomainName.Length -ne 0)
    {	
		Write-Host "[$(Get-Date)] The $computer is already in the domain!"
		break 
	}
	
	else
    {
		Set-ExecutionPolicy RemoteSigned
        $credential = New-Object System.Management.Automation.PSCredential($username,$password)
	    Add-Computer -ComputerName $computer -DomainName $domain -Credential $credential
        Write-Host "[$(Get-Date)] $computer join the $domain ok!"
        net localgroup administrators "DX\Domain Admins" /add
        Write-Host "[$(Get-Date)] Add DX\Domain Admins to Administrators group"
        net localgroup administrators "DX\IT OP" /add
        Write-Host "[$(Get-Date)] Add DX\IT OP Administrators group"
	}
}
JoinDomain  

 

退域脚本:

$domain = "域"
Write-Host ""
function LevelDomain
{	
    $computer = $env:COMPUTERNAME
	$DomainName = [System.Net.NetworkInformation.IPGlobalProperties]::GetIPGlobalProperties().DomainName

	if ($DomainName.length -ne 0)
    {	
        $username = "有权限的域账户"
        $password = "域账户密码" | ConvertTo-SecureString -asPlainText -Force
        $credential = New-Object System.Management.Automation.PSCredential($username,$password)
		remove-computer -credential $credential -PassThru -Force
        Write-Host "[$(Get-Date)] The $computer out of the domain: $domainName !"
	}
	else
    {
	    Write-Host "[$(Get-Date)] The $computer not in the domain: $domain !"
		break     
	}
}

LevelDomain 

 


内容更新于: 2018-03-15 14:31:46
链接地址: http://blog.leanote.com/post/benmo/windows%E5%8A%A0%E5%9F%9F-%E9%80%80%E5%9F%9F%E8%84%9A%E6%9C%AC

上一篇: ansible连接客户端selinux问题

下一篇: Redis

748 人读过
立即登录, 发表评论.
没有帐号? 立即注册
0 条评论
文档导航