Originally posted on May 7, 2022 @ 2:16 pm
Powershell query to clear up Active Directory user’s attribute in Bulk
In the last article, we saw how to export all users from Active Directory to an excel with the attributes you need. In case you missed to read the article, please follow this link.
In this article, we will create a CSV file for the users for whom we need to remove or clear the field for some specific attributes such as IPPhone, HomePhone etc.
My CSV will just have SAMAccountName as shown in the screenshot below:
I will name this csv as users1.csv and place this csv file in C:\ directory.
Here is the IP Phone and HomePhone attributes for the users.
As per the excel csv, we are going to apply the changes to Tom, John and Harry but not Chris. So when we run the bulk clearance attribute of Home and IP Phone number, it should not clear from Chris account but should clear from Tom, Harry and John’s account.
Powershell Script to clear the attributes in bulk:
$users = Import-Csv -Path C:\users1.csv
# Loop through CSV and update users if the exist in CVS file
foreach ($user in $users) {
#Search in specified OU and Update existing attributes
Get-ADUser -Filter “SamAccountName -eq ‘$($user.samaccountname)'” -Properties * -SearchBase “cn=Users,DC=uccollabing,DC=com” |
Set-ADUser -Clear l, ipphone, homephone
}
Time to see the results:
The results clearly shows that Chris account is intact with the IP Phone and Home Phone number whereas the users in the CSV file has been executed and the values were cleared successfully.
Hope you find it helpful!
I am working in an IT company and having 10+ years of experience into Cisco IP Telephony and Contact Center. I have worked on products like CUCM, CUC, UCCX, CME/CUE, IM&P, Voice Gateways, VG224, Gatekeepers, Attendant Console, Expressway, Mediasense, Asterisk, Microsoft Teams, Zoom etc. I am not an expert but i keep exploring whenever and wherever i can and share whatever i know. You can visit my LinkedIn profile by clicking on the icon below.
“Everyone you will ever meet knows something you don’t.” ― Bill Nye
Hi sir, im having this error: Error parsing query. can u help me on this? thanks