powershell导入AD用户和启用邮箱
2016-01-21 17:29
513 查看
导入ad账号,需要两个账号,ps文件和csv文件
ps文件:
Import-Csv -Encoding Unicode user.csv |foreach-Object{
$Nam=$_.name
$Givn=$_.givenname
$Surn=$_.surname
$Passw=$_.password
$Des=$_.description
$City=$_.city
$Emplyenum=$_.employeenumber
$Mobile=$_.mobilePhone
$com="@test.com"
$secure=ConvertTo-SecureString -string $Passw -asplaintext -force
New-ADUser -Name $Nam -SamAccountName $Nam -GivenName $Givn -Surname $Surn -Description $Des -DisplayName ($Surn+$Givn) -EmailAddress ($Nam+$com) -Enabled $true -PasswordNeverExpires $true -Path "OU=hr,DC=test,DC=com" -CannotChangePassword $false -ChangePasswordAtLogon $false -AccountPassword $secure -UserPrincipalName ($Nam+$com) -HomePage "www.test.com" -EmployeeNumber $Emplyenum -MobilePhone $Mobile -City $City
}
csv文件
放到同意目录下,运行ps脚本就可以添加用户。
下面的两条命令可以为添加的ad用户,启用邮箱
ps>Add-PSSnapin Microsoft.Exchange.Management.PowerShell.SnapIn
ps>Get-User -ResultSize unlimited -RecipientTypeDetails user| where {$_.userprincipalname -ne $null} |Enable-Mailbox -database mail1
本文出自 “绿光爸爸” 博客,请务必保留此出处http://lvguangbaba.blog.51cto.com/1271362/1737319
ps文件:
Import-Csv -Encoding Unicode user.csv |foreach-Object{
$Nam=$_.name
$Givn=$_.givenname
$Surn=$_.surname
$Passw=$_.password
$Des=$_.description
$City=$_.city
$Emplyenum=$_.employeenumber
$Mobile=$_.mobilePhone
$com="@test.com"
$secure=ConvertTo-SecureString -string $Passw -asplaintext -force
New-ADUser -Name $Nam -SamAccountName $Nam -GivenName $Givn -Surname $Surn -Description $Des -DisplayName ($Surn+$Givn) -EmailAddress ($Nam+$com) -Enabled $true -PasswordNeverExpires $true -Path "OU=hr,DC=test,DC=com" -CannotChangePassword $false -ChangePasswordAtLogon $false -AccountPassword $secure -UserPrincipalName ($Nam+$com) -HomePage "www.test.com" -EmployeeNumber $Emplyenum -MobilePhone $Mobile -City $City
}
csv文件
放到同意目录下,运行ps脚本就可以添加用户。
下面的两条命令可以为添加的ad用户,启用邮箱
ps>Add-PSSnapin Microsoft.Exchange.Management.PowerShell.SnapIn
ps>Get-User -ResultSize unlimited -RecipientTypeDetails user| where {$_.userprincipalname -ne $null} |Enable-Mailbox -database mail1
本文出自 “绿光爸爸” 博客,请务必保留此出处http://lvguangbaba.blog.51cto.com/1271362/1737319
相关文章推荐
- linux shell指令
- Shell小记:lsmod
- shell小记:lsdev
- bash环境下自动安装并初始化oh-my-zsh & autojump zsh
- SHELL _01
- Linux学习29_解决bash: 命令: command not found
- 数据库的shell命令导入导出
- 如何在java程序中调用linux命令或者shell脚本
- shell
- Shell Script 基础
- Oralce SQLPlus 以及shell脚本中spool输出到文件时的格式化输出
- shell按行处理文件
- Adb shell常用命令及用法
- 解决bash: mysql: command not found 的方法
- shell脚本 接受用户参数技巧一
- 通过adb shell 向android系统发送虚拟按键
- shell逻辑判断式与表达式
- shell脚本超时控制
- shell中$0,$?,$!等的特殊用法
- shell perl python 剖析