我想根据 CVS 文件中的名称将用户添加到组中

发布于 2024-12-13 11:47:16 字数 1409 浏览 1 评论 0原文

我有以下代码可以创建用户,但是当我在 CSV 文件中写入组时,用户不会添加到所述组中。 我可以在服务器上运行它。 该组是一个更大组的子组。所以我也不知道如何通知Powershell我想要一组一组。

这是可行的路径吗? BILOMNI.BILPROMETRIC.ROOT/EasyServe_OU/EasyServeChannel_OU/Channel_CenterUsers_OU

我也有组唯一名称 RequestingAccess_CenterUsers_GG

        $computer = $ENV:COMPUTERNAME;
        $users = Import-Csv "C:\Users.csv";

    Foreach ($user in $users)
    {
    #for ($i=0; $i -le 2000; $i++)
    #{
        # Grab required info
        $userName = $user.User
        $objOu = [ADSI]"WinNT://$computer"
        $Group = $user.Group

        # Create user
        $objUser = $objOU.Create("User", $userName + $i)
        $objUser.setpassword($user.password)
        $objUser.SetInfo()

        # Find target group and add the user to it
        $de = [ADSI]"WinNT://$computer/$Group,Group"
        $de.add([ADSI]"WinNT://$computer/$userName")

       # }
    }

    The following exception occurred while retrieving member "add": "An invalid dn syntax has been specified.
"
At C:\Users\dennis.hayden\Desktop\makingbilusers.ps1:20 char:12

+     $de.add <<<< ([ADSI]"LDAP://$computer/$userName")

    + CategoryInfo          : NotSpecified: (:) [], ExtendedTypeSystemException

    + FullyQualifiedErrorId : CatchFromBaseGetMember

下面是我使用的 CSV 文件:

User,Group,password

Masstestuser,RequestingAccess_CenterUsers_GG,P@ssWord

I have the following code that can make a user however when I write the group in the CSV file the user is not added to said group.
I am able to run this right on the server.
The group is in a sub-group of a much larger group. so I am also not sure how to inform Powershell I want a group of a group.

this is the path would this work?
BILOMNI.BILPROMETRIC.ROOT/EasyServe_OU/EasyServeChannel_OU/Channel_CenterUsers_OU

I also have the group unique name
RequestingAccess_CenterUsers_GG

        $computer = $ENV:COMPUTERNAME;
        $users = Import-Csv "C:\Users.csv";

    Foreach ($user in $users)
    {
    #for ($i=0; $i -le 2000; $i++)
    #{
        # Grab required info
        $userName = $user.User
        $objOu = [ADSI]"WinNT://$computer"
        $Group = $user.Group

        # Create user
        $objUser = $objOU.Create("User", $userName + $i)
        $objUser.setpassword($user.password)
        $objUser.SetInfo()

        # Find target group and add the user to it
        $de = [ADSI]"WinNT://$computer/$Group,Group"
        $de.add([ADSI]"WinNT://$computer/$userName")

       # }
    }

    The following exception occurred while retrieving member "add": "An invalid dn syntax has been specified.
"
At C:\Users\dennis.hayden\Desktop\makingbilusers.ps1:20 char:12

+     $de.add <<<< ([ADSI]"LDAP://$computer/$userName")

    + CategoryInfo          : NotSpecified: (:) [], ExtendedTypeSystemException

    + FullyQualifiedErrorId : CatchFromBaseGetMember

Below is the CSV file I am use:

User,Group,password

Masstestuser,RequestingAccess_CenterUsers_GG,P@ssWord

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

野生奥特曼 2024-12-20 11:47:16

您可以尝试通过 LDAP:// 更改所有 Wint:// 并修改一下您的代码,如下所示:

# Find target group and add the user to it
$de = [ADSI]"LDAP://$computer/$Group,Group"
$user=[ADSI]"LDAP://$computer/$userName"
$de.add($user.Path)

# Commit
$de.setinfo()

Can you try to change all your Wint:// by LDAP:// and modify a bit your code like the following :

# Find target group and add the user to it
$de = [ADSI]"LDAP://$computer/$Group,Group"
$user=[ADSI]"LDAP://$computer/$userName"
$de.add($user.Path)

# Commit
$de.setinfo()
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文