一些powershell指令

一、批量移動computer
$computer=get-adcomputer -filter * -searchabase "computer ou"|select name
foreach($i in $computer.name){dsquery computer -name $i |dsmove -newparent "new ou"}

二、批量禁用賬號
import-csv c:\xx.csv|foreach{disable-adacount -identity $_.name}


三、使用MOVE-ADobject批量移動電腦
    1.提供名單
    $com=import-csv d:\com.csv
    $com|foreach {get-adcomputer -identity $_.name} |select ObjectGUID |foreach {move-adobjec -identity $_.ObjectGUID -
    targetpath "ou=it,dc=it581,dc=local"}


四、批量開啓郵箱
    get-aduser -filter {name -like "Test*"} |select name | foreache { enable -mailbox -identity $_.name }

五、批量移動diabled的電腦
    Search-ADAccount -AccountDisabled -ComputersOnly | Move-ADObject -TargetPath "OU=discomputer,OU=IT
    ,DC=inovance,DC=local"

六、
#設置初始密碼
$password = "p@ssw0rd"
#輸入登錄名
$path = '.\Users.txt'
Import-Module ActiveDirectory
$usernames = Get-Content -Path $path
$secure_password = ConvertTo-SecureString -String $password -AsPlainText -Force
foreach($username in $usernames){
    try{
        Set-ADAccountPassword -Identity $username -NewPassword $secure_password  
    }
    catch{
        Write-Host "'$($username)'在AD中不存在,請檢查是否輸入有誤!" -ForegroundColor Red
    }  
}
cmd /c pause

七、批量移動computer
$a = Get-Content D:\citrix_Ctrl_test.txt #存放計算機名的文本文件
foreach($i in $a)
{
dsquery computer  -name $i | dsmove -newparent "OU=citrix_other,OU=Servers,OU=Citrix,DC=cicdev,DC=com" #將計算機名移動到citrix_other OU下
}

八、批量設置SMTP地址
1、準備一個CSV文件,可以有name和mailaddress字段即可
2、$user|%{set-mailbox -identity $_.name -emailaddress @{@=$_.mailaddress}}

這樣即可批量增加smtp地址了



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章