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

powershell分享5--AD中常用的小语句

时间:2018-03-29 15:55:05      阅读:188      评论:0      收藏:0      [点我收藏+]

标签:powershell

一、通过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),格式为:<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 # 为帐户指定新密码值。#
$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"    

}

二、导出指定OU下面所有人的一些信息

Get-ADUser -Filter -SearchBase "OU=测试公司,DC=demo,DC=com" -Properties | select Name,whenCreated,PasswordLastSet,SamAccountName | Export-CSV creat_time.csv -NoTypeInformation -Encoding UTF8

三、批量创建联系人

import-csv C:\Users\fanyxv\Desktop\contact.csv | ForEach {new-mailcontact -Alias $.Alias -name $.displayname -ExternalEmailAddress $.targetaddress}

powershell分享5--AD中常用的小语句

标签:powershell

原文地址:http://blog.51cto.com/fandecorator/2092453

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