码迷,mamicode.com
首页 > 系统相关 > 详细

一些powershell指令

时间:2017-10-19 19:58:58      阅读:254      评论:0      收藏:0      [点我收藏+]

标签: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地址了



本文出自 “cary_qin的博客” 博客,请务必保留此出处http://xpqinqun.blog.51cto.com/2136/1974285

一些powershell指令

标签:powershell

原文地址:http://xpqinqun.blog.51cto.com/2136/1974285

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!