建立一个PowerShell脚本文件ManagementUser.ps1
代码:
#设置接收的参数
param([string] $what,[string] $user,[string] $pwd)
#建立一个用户
function script:AddUser_ps($user,$pwd)
{
$spwd = ConvertTo-SecureString $pwd -AsPlainText -Force
import-module activedirectory
try
{
New-ADUser -Name $user -SamAccountName "test1" -UserPrincipalName $user"@test.com.cn" -GivenName "test1" -DisplayName "测试一" -path "ou=group1,dc=test,dc=com,dc=cn" -AccountPassword $spwd -Enabled $true -CannotChangePassword $false -ChangePasswordAtLogon $false -EmailAddress "test1@test.com.cn"