有人可以帮助我创建一个Powershell脚本,可以将现有用户添加为目录安全组的新成员吗?我没有Microsoft Active Directory服务器,我使用的是Zentyal Server,据我所知,它使用的是Samba3目录服务。
我能够使用以下Powershell脚本创建此LDAP服务器的新用户帐户,但我不知道如何将用户添加为名为Production的安全组的新成员。
这是用于向LDAP服务器添加新用户的powershell脚本。
# Server credential
$ldapServer = "LDAP://w.x.y.z/DC=acne,DC=local"
$ldapUsername = "[email protected]"
$ldapPassword = "user_password"
# Connect to the LDAP server
$conn = New-Object System.DirectoryServices.DirectoryEntries($ldapServer, $ldapUsername,
$ldapPassword)
$conn.AuthenticationType = [System.DirectoryServices.AuthenticationTypes]::Secure
$properties = @{
"sAMAccountName" = "user"
"userPrincipalName" = "[email protected]"
"userAccountControl" = 66048
"givenName" = "User"
"sn" = "One"
"displayName" = "User One"
}
# Add new user to the LDAP
$cn = "CN=" + $Props\["displayName"\] + ",CN=Users"
$newUser = $Conn.Children.Add($cn, "user")
foreach ($p in $Props.GetEnumerator()) {
$newUser.Properties\[$p.Key\].Value = $p.Value
}
$newUser.CommitChanges()
$newUser.Close()
我尝试使用属性“memberOf”,值为“cn=production,cn=users,dn=acme,dn=com”
1条答案
按热度按时间l2osamch1#
创建用户后:
您可以通过简单地将
Remove
方法替换为Add
方法来执行相同的操作以删除用户。请注意,这不适用于集成安全主体。对于这些,只有内置容器中的组可用,并且DN必须替换为SID,SID的字符串与
<SID=S-.*>
匹配