Some PowerShell instructions

Source: Internet
Author: User
Tags dsquery

First, Bulk mobile computer
$computer =get-adcomputer-filter *-searchabase "computer ou" |select name
foreach ($i in $computer. Name) {dsquery computer-name $i |dsmove-newparent "New OU"}

Second, bulk disable account
Import-csv c:\xx.csv|foreach{disable-adacount-identity $_.name}


Third, use Move-adobject bulk mobile computer
1. Provide a list
$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"}


Four, batch open mailbox
Get-aduser-filter {name-like "test*"} |select name | Foreache {enable-mailbox-identity $_.name}

Five, the bulk mobile diabled computer
search-adaccount-accountdisabled-computersonly | Move-adobject-targetpath "Ou=discomputer,ou=it
, dc=inovance,dc=local "

Six
#设置初始密码
$password = "[Email protected]"
#输入登录名
$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) ' does not exist in AD, please check if the input is incorrect! "-foregroundcolor Red
}
}
CMD/C Pause

Seven, bulk mobile 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" under #将计算机名移动到citrix_other OU
}

Eight, bulk set SMTP address
1, prepare a CSV file, you can have the name and MailAddress fields to
2, $user |%{set-mailbox-identity $_.name-emailaddress @{@=$_.mailaddress}}

This allows you to increase the SMTP address in bulk



This article is from the "Cary_qin blog" blog, make sure to keep this source http://xpqinqun.blog.51cto.com/2136/1974285

Some PowerShell instructions

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.