powershell - 在 PowerShell 中使用全局目录

标签 powershell active-directory

我的林中有多个域,我正在尝试编写一个可与​​林中的任何用户一起使用的脚本,因此我在我的脚本中使用了全局目录。

这可以检索数据,但是当我尝试修改我得到的数据时

Set-ADUser : The server is unwilling to process the request

如果我使用域 Controller (DC) 作为服务器名称,修改将按预期完成。我想避免编写一个开关来设置服务器名称。还有什么我可以在这里做的吗?

Get-ADUser $user -Server "contoso.local:3268" | %{Set-ADUser -Identity $_.distinguishedname -SamAccountName $_.SamAccountName -Server "contoso.local:3268"}

最佳答案

我不太清楚您要在这里做什么。全局目录端口是只读的(对于 LDAP)。

如果您想确保找到一个作为全局目录的域 Controller ,您可以使用以下命令:

Get-ADDomainController -Discover -Service GlobalCatalog

根据您的评论,maybe what you need is $PSDefaultParameterValues :

$PSDefaultParameterValues = @{
    "*-AD*:Server" = "contoso.local:3268"
}

Get-ADUser $user |
%{Set-ADUser -Identity $_.distinguishedname -SamAccountName $_.SamAccountName }

关于powershell - 在 PowerShell 中使用全局目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33654523/

相关文章:

powershell - 在 PowerShell 中设置文本颜色

regex - 从Powershell中的变量中提取数字

xml - 具有命名空间的 PowerShell XML 选择节点

visual-studio - 在 Visual Studio 2015 中加载解决方案时运行 PS1

c# - 密码过期时如何在事件目录中更改密码

powershell - 使用Powershell过滤get-adobject

javax.命名.AuthenticationException

c# - Windows XP 上出现PrincipalServerDownException,但 Windows 7 上没有

powershell - 如何在 PowerShell 中删除重音符号?

powershell - 如何使用 powershell 过滤 vim 中的行