none
get-aduser -filter "company -eq 'domainname'" | foreach {set-aduser $_ -Replace @{c="NL";co="Netherlands";countrycode=31}} RRS feed

  • Question

  • In powershell on a domaincontroller i would like to set the country, countrycode and c attribute. This is needed becauser i want to set the usagelocation in Azure AD. Our AD is synced to Azuread and we cannot assign licenses to users because this attribute is not set.

    So i did some digging on the internet and the following should do the job for all users in all OU's in Active Directory, however the command is executed but nothing changes in the attributes of all users, no error appears.

    What is wrond with the command is it that in stead of domain name there should be something else?

    get-aduser -filter "company -eq 'domainname'" | foreach {set-aduser $_ -Replace @{c="NL";co="Netherlands";countrycode=31}}


    freddie

    Saturday, March 21, 2020 9:07 AM

All replies

  • What do you think you need?  It is your AD and your company.  What company name do you want to filter on?  We cannot possibly answer that for you.

    The correct syntax is as follows.

    $replace = @{
        c = 'NL'
        co = 'Netherlands'
        countrycode = 31
    }
    Get-AdUser -filter "company -eq 'domainname'" | 
        Set-AdUser -Replace $replace -Verbose


    \_(ツ)_/


    • Edited by jrv Saturday, March 21, 2020 11:01 AM
    Saturday, March 21, 2020 10:35 AM
  • Also note that the CountryCode for Netherlands is 528 and not 31. "31" is the telephone code and will not work correctly in Windows if used as the CC.

    \_(ツ)_/

    Saturday, March 21, 2020 11:11 AM