PowerShell share small statements commonly used in 5--ad

Source: Internet
Author: User
Tags samaccountname

I. Bulk mailbox creation via PowerShell
Set-Location C:\Users\fanyx_v\Desktop\

Import-module ActiveDirectory
Add-pssnapin microsoft.exchange*
Add-pssnapin Microsoft.Exchange.Management.PowerShell.SnapIn
$ADUser =import-csv-path. \newuser.csv-useculture-encoding Default
foreach ($Users in $ADUser)
{
$UserPrincipalName = $Users. userPrincipalName #每个用户帐户都有用户主体名称 (UPN), formatted as:<user>@<dns-domain-name>. #
# $Company = $Users. Company #指定用户所在的公司. #
$Department = $Users. Department #指定用户所在的部门. #
$DisplayName = $Users. DisplayName #指定对象的显示名称. #
$Name = $Users. Name #指定对象的名称. #
$SamAccountName = $Users. sAMAccountName
$Description = $Users. Description #账户的描述信息 #
$Manager = $Users. Manager #指定用户的经理. #
# $AccountPassword = $Users. Accountpassword # Specify a new password value for the account. #
$MobilePhone = $Users. Mobilephone #指定用户的移动电话号码.
$AccountExpirationDate = $Users. accountExpirationDate #指定用户的过期时间

    #根据需要添加New-ADUser -Name $Name -Manager  $Manager  -AccountExpirationDate $AccountExpirationDate  -UserPrincipalName  $UserPrincipalName -Department  $Department   -SamAccountName $SamAccountName   -DisplayName  $DisplayName  -Description $Description   -ChangePasswordAtLogon 0 -AccountPassword (ConvertTo-SecureString "2q3eNChZ" -AsPlainText -Force) -Enabled 1 -Path "OU=测试公司,DC=demo,DC=com"sleep 20 #延迟数Enable-Mailbox  $users.SamAccountName -Database "database"    

}

Second, export some information for everyone under the specified OU

Get-aduser-filter -searchbase "ou= test company, dc=demo,dc=com"-properties | Select Name,whencreated,passwordlastset,samaccountname | Export-csv creat_time.csv-notypeinformation-encoding UTF8

Third, bulk create contacts

Import-csv C:\Users\fanyxV\desktop\contact.csv | ForEach {New-mailcontact-alias $. Alias-name $. displayname-externalemailaddress $. targetaddress}

PowerShell share small statements commonly used in 5--ad

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.