简体   繁体   English

函数返回的数据类型

[英]Function Returned Data Type

I've written a function that will create an Active Directory user based on the supplied parameters. 我编写了一个函数,它将根据提供的参数创建一个Active Directory用户。 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数据,以防止该数据被该函数返回。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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