AD域控批量运维管理名
  WrKbzYIY5GyU 2023年11月02日 25 0

注意:以下操作都需要已管理员权限运行powersehll命令才行执行成功。

1 批量创建计算机账户

$ouPath = "OU=computer,OU=Citrix,DC=citrixlab,DC=local"
1..100 | ForEach-Object {
    $computerNumber = $_.ToString("000") #此为占位符
    $computerName = "CVAD-$computerNumber"
    New-ADComputer -Name $computerName -Path $ouPath
}

2 批量创建AD域账号

$ouPath = "OU=Citrix,DC=citrixlab,DC=local"
$csvPath = "C:\Path\to\input.csv"
$users = Import-Csv -Path $csvPath
foreach ($user in $users) {
    $userName = $user.UserName
    $password = ConvertTo-SecureString -String $user.Password -AsPlainText -Force

    $userParams = @{
        SamAccountName = $userName
        UserPrincipalName = "$userName@citrixlab.local"
        Name = $userName
        GivenName = $user.FirstName
        Surname = $user.LastName
        DisplayName = $user.DisplayName
        Path = $ouPath
        AccountPassword = $password
        Enabled = $true
    }
    
    New-ADUser @userParams
}

3 批量移动指定OU下计算机账户到另外OU

$sourceOU = "OU=Computers,OU=DepartmentA,DC=example,DC=com"
$targetOU = "OU=VDI Computers,OU=DepartmentB,DC=example,DC=com"

$filter = {
    Name -like "VDI*"
}

$computers = Get-ADComputer -Filter $filter -SearchBase $sourceOU

foreach ($computer in $computers) {
    Move-ADObject -Identity $computer -TargetPath $targetOU
}

4 按条件删除指定OU下的计算机账户

$ouPath = "OU=Computers,OU=DepartmentA,DC=example,DC=com"

$filter = {
    Enabled -eq $true -and #选择禁用的
    OperatingSystem -like "*Server*" -and #选择是server的系统
    (Search-ADAccount -ComputersOnly -AccountDisabled).Count -eq 0 -and #排除已禁用的计算机
    Description -eq "To be deleted" 
}

$computers = Get-ADComputer -Filter $filter -SearchBase $ouPath

foreach ($computer in $computers) {
    Remove-ADComputer -Identity $computer -Confirm:$false
}

5 按条件删除指定OU下的域账号

$ouPath = "OU=Users,OU=DepartmentA,DC=example,DC=com"

$filter = {
    Enabled -eq $true -and
    (Search-ADAccount -UsersOnly -AccountDisabled).Count -eq 0 -and
    Description -eq "To be deleted"
}

$users = Get-ADUser -Filter $filter -SearchBase $ouPath

foreach ($user in $users) {
    Remove-ADUser -Identity $user -Confirm:$false -Recursive -Force
}
【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

  1. 分享:
最后一次编辑于 2023年11月08日 0

暂无评论

推荐阅读
  KRsXEGSB49bk   2023年11月24日   39   0   0 Server客户端加载
  OGG2zAst6hx8   2023年11月26日   29   0   0 bootstrapServerkafka
  zNxK8cIqmu7p   2023年11月19日   31   0   0 ServerAPIPod
  it2nV7RK7uw1   2023年11月28日   75   0   0 DockerServerIP