Using a global catalog in PowerShell

会有一股神秘感。 提交于 2020-03-20 09:12:18

问题


I have multiple domains in my forest, and I'm trying to write a script that will work with any user in the forest, so I'm using a global catalog in my script.

This works to retrieve the data, but when I try and modify the data I'm getting

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

If I use the domain controller (DC) as the server name, the modification completes as it should. I'd like to avoid writing a switch to set the server name. Is there anything else I can do here?

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

回答1:


I'm not really clear on what you're trying to do here. Global catalog ports are read only (for LDAP).

If you want to make sure you find a domain controller that is a global catalog, you can use the following:

Get-ADDomainController -Discover -Service GlobalCatalog

Based on your comment, maybe what you need is $PSDefaultParameterValues:

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

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


来源:https://stackoverflow.com/questions/33654523/using-a-global-catalog-in-powershell

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!