2012-03-07 40 views
0

我使用PowerShell的移動用戶在不同的領域不同的OU證書與未經Quest/ADAM /的cmdlet

[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") 

我recive一個 「常規訪問被拒絕」 的錯誤。由於我需要權利這一事實。這工作雖然。

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

記住,這是沒有任務,ADAM非2008的服務器上一樣,cmdlet不工作。我有工作的唯一的事情是:

「添加型-AssemblyName System.DirectoryServices.AccountManagement」

我需要沿着此線的東西:

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

回答

0

你似乎是在正確的軌道上。你在目標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) 

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

+0

這是我遇到麻煩的權限!我通過「[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')」解決方案! – 2012-03-08 07:50:06

0

想通了:

[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) 

一會兒拿了!