2012-02-08 59 views
0

我使用我的帳戶登錄了域「domain1」。我希望通過powershell能夠通過密碼爲「password1」的supe ruser賬戶「suaccount」更新域「domain2」中的用戶。信任在兩者之間建立。Powershell CMDLET跨域管理

運行PowerShell 2.0和.NET 3.5 SP1

我已經遠遠此得到:

Add-Type -AssemblyName System.DirectoryServices.AccountManagement 
$ctype = [System.DirectoryServices.AccountManagement.ContextType]::Domain 
$context = New-Object -TypeName  
System.DirectoryServices.AccountManagement.PrincipalContext -ArgumentList $ctype, "domain2", "OU=TestOU,DC=domain2", "suaccount", "password1" 

$usr = New-Object -TypeName System.DirectoryServices.AccountManagement.UserPrincipal -ArgumentList $context 

$usr.Name = "AM Test1" 
$usr.DisplayName = "AM Test1" 
$usr.GivenName = "AM" 
$usr.SurName = "Test1" 
$usr.SamAccountName = "AMTest1" 
$usr.UserPrincipalName = "[email protected]" 

$usr.PasswordNotRequired = $false 
$usr.SetPassword("errr") 
$usr.Enabled = $true 

$usr.Save() 

相當新的PowerShell的,任何指針?我想編輯/創建「其他」域上的用戶可以這麼說。

我得到的錯誤:

"Exception calling "Save" with "0" argument(s): "General access denied error 
" 
At C:\Script\Sandbox\Morris PowerShell Application\includes\mo\mo.ps1:104 char:14 
+  $usr.Save <<<<() 
    + CategoryInfo   : NotSpecified: (:) [], MethodInvocationException 
    + FullyQualifiedErrorId : DotNetMethodException" 

任何指針?

+1

域2信任域1嗎? – 2012-02-08 09:42:42

+0

是的,兩者之間建立了信任! – 2012-02-08 10:13:16

+0

Domain2的FQDN是什麼? – 2012-02-08 10:19:02

回答

0

From comments:嘗試使用用戶名這種格式domain2 \ username,並始終使用該域的FQDN。 - 基督徒昨天