Change Country, Country Code via Powershell for a specific OU

Stefanos Constantinou 61 Reputation points
2020-12-17T12:56:29.173+00:00

Hello everyone,

I have been trying to get a working command via Powershell on AD server which will change C, Country, CountryCode for a specific OU

Get-ADUser -SearchBase 'OU=Test OU,OU=Users and Computers,OU=Company HQ,DC=DOMAIN,DC=com' -filter * | ForEach {Set-ADUser -Identity * -c="IT" -co="Italy" -countryCode="380"}

no luck with the result with the brackets or without {} after the pipeline

Windows for business Windows Client for IT Pros Directory services Active Directory
Windows for business Windows Server User experience PowerShell
0 comments No comments
{count} votes

Accepted answer
  1. Anonymous
    2020-12-18T07:10:54.34+00:00

    Hi,

    Use -replace to set these properties as there are no corresponding parameters for them

    Get-ADUser -SearchBase 'OU=Test OU,OU=Users and Computers,OU=Company HQ,DC=DOMAIN,DC=com' -filter * | Set-ADUser -Replace @{c="IT";co="Italy";countryCode="380"}  
    

    Best Regards,
    Ian Xue

    ============================================

    If the Answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


1 additional answer

Sort by: Most helpful
  1. Rich Matheisen 47,901 Reputation points
    2020-12-17T16:05:58.73+00:00

    Remove the "-Identity *" from the Set-ADUser. You're already piping all the user accounts from the Get-ADUser.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.