我编写了一个函数,它将根据提供的参数创建一个 Active Directory 用户。用户创造精品;但是我遇到的问题是函数返回的数据。我只是想根据用户是否创建返回一个布尔响应。相反,它传回了一个数组。
函数示例:
Function CreateUser () {
param([string]$ParentDN,
[string]$FirstName,
[string]$LastName,
[string]$Username,
[string]$EmailAddress,
[string]$Password);
Try {
$UserOU = [ADSI] "LDAP://$LDAPServer/$ParentDN";
$NewUser = $UserOU.Create("user","cn=$Username");
$NewUser.Put("sAMAccountName","$Username");
$NewUser.Put("givenName","$FirstName");
$NewUser.Put("sn","$LastName");
$NewUser.Put("UserPrincipalName","$Username@$NetworkFQDN");
$NewUser.Put("mail","$EmailAddress");
$NewUser.SetInfo();
$NewUser.SetPassword("$Password");
$NewUser.SetInfo();
$flag = $NewUser.userAccountControl.Value -bxor 65536; #Password Never Expires flag
$NewUser.userAccountControl = $flag;
$NewUser.InvokeSet("AccountDisabled","False") #Enables Account
$NewUser.SetInfo();
return $true;
}
Catch {
return $false;
}
}
我使用以下语法调用它:
$CreateUserResults = CreateUser -FirstName $User_FirstName -LastName $User_LastName -EmailAddress $User_EmailAddress -ParentDN $User_ParentOU -Password $User_Password -Username $User_SamAccountName
任何建议或方向将不胜感激。
谢谢,瑞安