简体   繁体   中英

Function Returned Data Type

I've written a function that will create an Active Directory user based on the supplied parameters. The user creates fine; however the problem that I'm running into is the returned data from the function. I'm merely looking to return a boolean response based on if the user was created or not. Instead, it's passing back an array.

A sample of the function:

    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;
      }
    }

And I'm calling it using the following syntax:

 $CreateUserResults = CreateUser -FirstName $User_FirstName -LastName $User_LastName -EmailAddress $User_EmailAddress -ParentDN $User_ParentOU -Password $User_Password -Username $User_SamAccountName

Any advise or direction would be appreciated.

Thanks, Ryan

我不是可以测试的地方,但是我怀疑那些setinfo()方法正在返回需要重定向到$null数据,以防止该数据被该函数返回。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM