Powershell - Remove multiple extensionAtrribs

Larry David
Larry David used Ask the Experts™

Looking to remove/clear multiple extensionattributes in AD by EmployeeID.

I have a .csv full of employeeID’s that need all of their extensionAtrribs cleared out
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2018
Distinguished Expert 2018
This should do the trick.
It's in test mode and will only display which attributes it would clear. Remove the -WhatIf at the end of line 6 to run it for real.
Import-Csv -Path C:\Temp\employeeid.csv | ForEach-Object {
	If ($adUser = Get-ADUser -Filter "employeeId -eq '$($_.employeeId)'" -Property *) {
		Write-Host "Clearing extensionAttributes for '$($adUser.SamAccountName)' ..."
		If ($clear = @($adUser.PropertyNames) | Where-Object {($_ -like 'extensionAttribute*') -and ($adUser.$_)}) {
			Write-Host "... $($clear -join ', ')"
			Set-ADUser -Identity $adUser -Clear $clear -WhatIf
		} Else {
			Write-Host "... no extensionAttribute found to clear."
	} Else {
		Write-Warning "No user found with employeeId '$($_.employeeId)'"

Open in new window


Awesome! Worked out beautifully

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial