powershell脚本实现计算机加入域

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/YOLO3/article/details/81118239

Function Set-Domain 

    param 
    (
        [Parameter(Mandatory = $true, Position = 0)] [string] $DNS,
        [Parameter(Mandatory = $true, Position = 1)] [string] $Domain, 
        [Parameter(Mandatory = $true, Position = 2)] [string] $Password,
        [Parameter(Mandatory = $true, Position = 3)] [string] $UserName
    )
    
    $wmi = Get-WmiObject win32_networkadapterconfiguration -filter "ipenabled = 'true'"
    
    #设置DNS
    $wmi.SetDNSServerSearchOrder($DNS) >$null    
    
    #加入域
    $pwd = $Password | ConvertTo-SecureString -asPlainText -Force 
    $credential = New-Object System.Management.Automation.PSCredential($UserName,$pwd) 
    Add-Computer -DomainName $Domain -Credential $credential 

    write-host success!
    Restart-Computer -Force
}

没有更多推荐了,返回首页