Answered by:
Removing Specific Attribute For List Of Users

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
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)
- Edited by Richard MuellerMVP Wednesday, November 20, 2019 2:31 PM
- Marked as answer by Charlie4872 Wednesday, November 20, 2019 3:34 PM
All replies
-
-
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
-
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)
- Edited by Richard MuellerMVP Wednesday, November 20, 2019 2:31 PM
- Marked as answer by Charlie4872 Wednesday, November 20, 2019 3:34 PM
-
-
-