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

Active Directory
Active Directory
A set of directory-based technologies included in Windows Server.
6,451 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,511 questions
0 comments No comments
{count} votes

Accepted answer
  1. Ian Xue 36,336 Reputation points Microsoft Vendor
    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 46,556 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.