【问题标题】:PowerShell Move User to different OU in different Domain with Credentials without Quest/ADAM/CmdletsPowerShell 使用没有 Quest/ADAM/Cmdlet 的凭据将用户移动到不同域中的不同 OU
【发布时间】:2012-03-08 18:11:49
【问题描述】:

我正在使用

[System.DirectoryServices.AccountManagement.UserPrincipal]::FindByIdentity($context, $idtype, $sam)

如何将此用途转移到新的 OU?

我试过了:

...
$user_adspath = $user.Properties.adspath
$user_ou = [ADSI]"$user_adspath"
$user_ou.PSBase.MoveTo("LDAP://$target")

我收到“拒绝常规访问”错误。因为我需要权利。不过这行得通。

...
$user.description += " MOVED"
$user.Enabled = $False
$user.Save()

请记住,这是在没有 Quest、ADAM、Cmdlet 的非 2008 服务器上无法运行的。我唯一的工作是:

“Add-Type -AssemblyName System.DirectoryServices.AccountManagement”

我需要一些类似的东西:

$user.MoveTo("LDAP://$target")
$user.Save()

【问题讨论】:

    标签: powershell


    【解决方案1】:

    您似乎走在了正确的轨道上。您在目标 OU 中具有写入权限吗?应该就这么简单:

    [adsi]$OU="LDAP://OU=Disabled Accounts,OU=Employees,DC=mycompany,DC=local"
    [adsi]$User="LDAP://CN=Art Deco,OU=Sales,OU=Employees,DC=mycompany,DC=local"
    $user.psbase.Moveto($OU)
    

    您不需要加载任何程序集或使用其他任何东西。

    【讨论】:

    • 这是我遇到问题的权限!我通过“[System.DirectoryServices.AccountManagement.UserPrincipal]::FindByIdentity($context, $idtype, $sam)”登录到另一个域,这将返回“$user”,我在其中执行以下命令“ $user.description += " MOVED" $user.Enabled = $False $user.Save()" 成功!因此,为什么我需要“$user.invoke('ou','LDAP://CN=Art Deco,OU=Sales,OU=Employees,DC=mycompany,DC=local','sAMAccountName=xxxx')”解决方案!
    【解决方案2】:

    想通了:

    [adsi]$dest = New-Object System.DirectoryServices.DirectoryEntry ("LDAP://ou=somwhere,dc=company,dc=local","domain\username","password") 
    $user_move = New-Object System.DirectoryServices.DirectoryEntry ("LDAP://cn=user,ou=somehow,dc=company,dc=local","domain\username","password")
    $user_move.PSBase.MoveTo($dest)
    

    花了一点时间!

    【讨论】:

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