【问题标题】:PowerShell - How do I add a User to an AD User Group using ADSI and alternate credentialsPowerShell - 如何使用 ADSI 和备用凭据将用户添加到 AD 用户组
【发布时间】:2019-12-09 21:52:15
【问题描述】:

我需要使用特定凭据将用户添加到 AD 组,但无法解决这个问题....这是我目前所拥有的,在检索成员“添加”时出现“未指定错误”。必须使用 ADSI 完成,因为 AD 模块在我的场景中不起作用。

$CredsUserName = 'domain\user'
$CredsPassword = 'password'

$GroupPath = "LDAP://CN=<UserGroup>...."
$UserPath = "LDAP://CN=<UserDN>...."
$Group = [ADSI]$GroupPath
$User = [ADSI]$UserPath

$GroupArgs = New-Object -TypeName System.DirectoryServices.DirectoryEntry -ArgumentList $Group, "$CredsUserName", "$CredsPassword"

$GroupArgs.Add($User.adspath)

【问题讨论】:

    标签: powershell active-directory adsi


    【解决方案1】:

    试试这个:

    $CredsUserName = 'domain\user'
    $CredsPassword = 'password'
    $Domain = "<FQDN of the AD domain>/"
    
    $GroupPath = "CN=<UserGroup>...."
    $UserPath = "CN=<UserDN>...."
    
    $Group = [adsi]::new("LDAP://$($Domain)$($GroupPath)",$CredsUserName,$CredsPassword)
    $Group.member.Add($UserPath)
    $Group.CommitChanges()
    

    仅当您使用的计算机不属于包含该组的 AD 域时,您才需要 $Domain。

    问候,

    斯图尔特。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-14
      • 1970-01-01
      • 2020-04-02
      相关资源
      最近更新 更多