none
Removing Specific Attribute For List Of Users RRS feed

  • Question

  • I have been scouring the Internet and cannot find a way to remove or clear an AD attribute for only a list of user accounts. The command that I think will do the job is...

    get-aduser -filter {msRTCSIP-PrimaryUserAddress -like "*"}|set-aduser -clear msRTCSIP-PrimaryUserAddress,msRTCSIP-PrimaryHomeServer,msRTCSIP-UserEnabled,msRTCSIP-OptionFlags,msRTCSIP-UserPolicies

    But I dont want to run this on every user account in AD. Is there a way to modify this command to point it to a .txt file with a list? of usernames or email addresses and run it just on those accounts?



    Chad Guiney

    Tuesday, November 19, 2019 9:45 PM

Answers

  • I would suggest similar to the following:

    Get-Content c:\Temp\Users.txt | ForEach {
        Set-ADUser -Identity $_ -Clear msRTCSIP-PrimaryUserAddress, msRTCSIP-PrimaryHomeServer, msRTCSIP-UserEnabled, msRTCSIP-OptionFlags, msRTCSIP-UserPolicies, msRTCSIP-DeploymentLocator
    }
    Edit: The text file should be a list of the sAMAccountNames of the users. If the list is something else, like email addresses, then more code is required to retrieve the user, and ensure that one and only one is retrieved.


    Richard Mueller - MVP Enterprise Mobility (Identity and Access)


    Wednesday, November 20, 2019 2:28 PM

All replies

  • Sure.

    Get-Content <yourfile.txt> |
        foreach {
           <your-code-here>
       }


    --- Rich Matheisen MCSE&I, Exchange Ex-MVP (16 years)

    Tuesday, November 19, 2019 10:02 PM
  • Thanks for the reply Rich this seems to work but when I ran the script below it still looks like it is running on all AD accounts. Is there something I need to change to make sure it only makes the changes on the users listed in the users.txt file?

    Get-Content c:\temp\users.txt |
        foreach {
    get-aduser -filter {samaccountname -like "*"}|set-aduser -clear msRTCSIP-PrimaryUserAddress,msRTCSIP-PrimaryHomeServer,msRTCSIP-UserEnabled,msRTCSIP-OptionFlags,msRTCSIP-UserPolicies,msRTCSIP-DeploymentLocator
       }

    Thanks again for the quick reply!


    Chad Guiney

    Wednesday, November 20, 2019 1:34 PM
  • I would suggest similar to the following:

    Get-Content c:\Temp\Users.txt | ForEach {
        Set-ADUser -Identity $_ -Clear msRTCSIP-PrimaryUserAddress, msRTCSIP-PrimaryHomeServer, msRTCSIP-UserEnabled, msRTCSIP-OptionFlags, msRTCSIP-UserPolicies, msRTCSIP-DeploymentLocator
    }
    Edit: The text file should be a list of the sAMAccountNames of the users. If the list is something else, like email addresses, then more code is required to retrieve the user, and ensure that one and only one is retrieved.


    Richard Mueller - MVP Enterprise Mobility (Identity and Access)


    Wednesday, November 20, 2019 2:28 PM
  • This worked perfectly! Thanks Richard. Had to convert my list of users' email addresses to samaccountname via another script but once that was done it worked great!

    Thanks!


    Chad Guiney

    Wednesday, November 20, 2019 3:34 PM
  • You are welcome. Glad it worked!

    Richard Mueller - MVP Enterprise Mobility (Identity and Access)

    Wednesday, November 20, 2019 8:40 PM
  • Well, that's what your filter says! You want to use, say, "$_" where you have "*" -- assuming the file has only samaccount names in it.

    --- Rich Matheisen MCSE&I, Exchange Ex-MVP (16 years)

    Thursday, November 21, 2019 8:00 PM