none
AD Users Change Company Name RRS feed

  • Question

  • Hi Guys, 

    how can I change a company name attribute for all users from selected OUs?

     I tried:

     $Users = Get-ADUser -SearchBase $OU -Filter *
    Set-ADUser -Identity $Users -Company $NewCompanyName

    But Then I get error 
    Set-ADUser : Cannot convert 'System.Object[]' to the type 'Microsoft.ActiveDirectory.Management.ADUser' required by parameter 'Identity'. Specified method
     is not supported.
    Thanks For help :) 


    • Edited by LuLaCeK Tuesday, November 19, 2019 9:58 AM
    Tuesday, November 19, 2019 9:56 AM

Answers

  • Hi LuLaCek,

    You can not pass array object at a same time, use Foreach to do the same:

    $Users = Get-ADUser -SearchBase $OU -Filter *
    $users|Foreach {
             Set-ADUser -Identity $_ -Company $NewCompanyName
         }


    • Edited by Imran_Khan Tuesday, November 19, 2019 10:07 AM
    • Marked as answer by LuLaCeK Tuesday, November 19, 2019 10:10 AM
    Tuesday, November 19, 2019 10:06 AM

All replies

  • You can only use one name at a time. Please refer tto the documentation for instructions:

    help set-aduser -online


    \_(ツ)_/

    Tuesday, November 19, 2019 10:04 AM
    Moderator
  • Hi LuLaCek,

    You can not pass array object at a same time, use Foreach to do the same:

    $Users = Get-ADUser -SearchBase $OU -Filter *
    $users|Foreach {
             Set-ADUser -Identity $_ -Company $NewCompanyName
         }


    • Edited by Imran_Khan Tuesday, November 19, 2019 10:07 AM
    • Marked as answer by LuLaCeK Tuesday, November 19, 2019 10:10 AM
    Tuesday, November 19, 2019 10:06 AM
  • Works like a charm ^^

    Thanks :) 

    Tuesday, November 19, 2019 10:10 AM