2012-03-07 9 views
0

私は新しいOUにこの使用を移動するにはどうすればよいPowerShellの移動ユーザー

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

を使用していますか?

私が試してみた:

... 
$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年サーバーではないことを覚えておいてください。コマンドレットは機能しません。私が持っている唯一のものの作業は次のとおりです。

「追加型-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')ソリューションが必要です! –

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) 

はしばらくかかりました!

関連する問題