0

我有下面的代碼可以讓用戶,但是當我在CSV文件中編寫組時,用戶不會添加到所述組中。 我能夠在服務器上運行這個權利。 該組是在一個更大的組中的一個子組。所以我也不確定如何通知Powershell我想要一組小組。我想添加一個用戶到一個基於名稱的CVS文件組

這是工作的路徑嗎? 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,[email protected] 
+0

你真的在'工作組'中工作,或者你在域中工作? – JPBlanc

+0

我相信一個域名組有一個獨特的名字,所以我不確定爲什麼我不能使用它。 –

+0

如果你在一個域上工作,你在Active-Directory上,所以最好用「LDAP://」代替「WinNT://」 – JPBlanc

回答

1

你能嘗試更改所有Wint://LDAP://並修改一下您的代碼,如下所示:

# 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() 
+0

如果我更改這一行代碼會中斷,甚至不會添加用戶。 $ objOu = [ADSI]「WinNT:// $ computer」 –

+0

您仍然使用Winnt!給你一點csv,今晚我會看看。 – JPBlanc

+0

我不明白的是,如果我說一個簡單的團體說客人腳本仍然無法正常工作。我嘗試了$電腦+「/」+「嘉賓」。所以它使用一個組路徑爲什麼是這樣的?這麼辛苦? CSV被添加到OP的末尾 –

相關問題