Search code examples
powershellactive-directory

Using a global catalog in PowerShell


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"}

Solution

  • 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 }