温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

一些powershell指令

发布时间:2020-07-24 06:45:13 来源:网络 阅读:609 作者:风信子0311 栏目:系统运维

一、批量移动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地址了



向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI