Skip to content

Instantly share code, notes, and snippets.

@XPlantefeve
Created March 19, 2015 16:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save XPlantefeve/4a1a2728e7879a339bef to your computer and use it in GitHub Desktop.
Save XPlantefeve/4a1a2728e7879a339bef to your computer and use it in GitHub Desktop.
Get faulty ADM accounts ('adm-username' for which there's no 'username')
Function Get-ADReferent ($user)
{
$user = $user -replace '^adm-',''
Try {
$test = Get-ADUser $user
$test.SamAccountName
} Catch {
''
}
}
Get-ADUser -filter 'name -like "adm-*"' |
foreach {
New-Object -TypeName PSObject -Property @{
'SamAccountName' = $_.SamAccountName
'DistinguishedName' = $_.DistinguishedName
'ReferentAccount' = Get-ADReferent $_.SamAccountName
}
} |
where ReferentAccount -eq '' |
select SamAccountName,DistinguishedName
# export-csv -Path admaccounts.csv
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment