Powershell CMDLET跨域管理

时间:2012-02-08 09:35:20

标签: powershell

我已使用我的帐户登录域“domain1”。我希望通过powershell能够通过我的supe ruser帐户“suaccount”用密码“password1”更新域“domain2”中的用户。信任在两者之间建立。

运行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 = "amtest1@mtest.test"

$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 个答案:

答案 0 :(得分:0)

来自评论:尝试使用此格式为domain2 \ username的用户名,并始终使用域的FQDN。 - 昨天的基督徒