Link to home
Start Free TrialLog in
Avatar of dlo32
dlo32

asked on

Powershell script to locate any user object with a duplicate or blank ExtensionAttribute

I need some help from someone versed in Powershell.  I am trying to locate user objects that have either a duplicate value for ExtensionAttribute11, or have are blank/null value.

Anyone have something similar in a separate scripts or know how best to create this?
Avatar of becraig
becraig
Flag of United States of America image

$userlist = Get-ADUser -Filter { Enabled -eq $true } -Properties ExtensionAttribute11
$dupes = @{}; $userlist |% { if($_.ExtensionAttribute11) { $dupes [$_.ExtensionAttribute11] += 1 } }
$DupeList = $userlist | ? { if($_.ExtensionAttribute11) { $dupes [$_.ExtensionAttribute11] -gt 1 } }
$NullList = $userlist | ? { $_.ExtensionAttribute11-eq $null -or $_.ExtensionAttribute11 -eq ""} 
$DupeList| Select-Object -Property $_.displayname, ExtensionAttribute11
$NullList | Select-Object -Property $_.displayname, ExtensionAttribute11

Open in new window



Something like this should work
ASKER CERTIFIED SOLUTION
Avatar of oBdA
oBdA

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of dlo32
dlo32

ASKER

THANK YOU!!!!
Avatar of dlo32

ASKER

Hello - LVL85 - Is there an easy way to add the organizational unit that the duplicate accounts are located in?
Is there an easy way to add the organizational unit that the duplicate accounts are located in?

Modified the script by oBdA to show the CanonicalName property as well:

$Attribute = 'ExtensionAttribute11'
$ADUsers = Get-ADUser -Filter * -ResultSetSize $Null -Properties $Attribute, CanonicalName | Select-Object -Property SamAccountName, CanonicalName, $Attribute, @{n='Duplicate'; e={}}
$ADUsers | Where-Object {-not $_.$Attribute}
$ADUsers | Where-Object {$_.$Attribute} | Group-Object -Property $Attribute | Where-Object {$_.Count -gt 1} | ForEach-Object {
	$Duplicates = ($_.Group | Select-Object -ExpandProperty SamAccountName | Sort-Object) -join ', '
	$_.Group | Select-Object -Property SamAccountName, CanonicalName, $Attribute, @{n='Duplicate'; e={$Duplicates}}
}

Open in new window


Works for me, hope this helps anyone.