So I am in the process of learning PowerShell in the hopes of cleaning up active directory and was looking for a little help, My issue is that multiple users may share multiple proxy addresses but no two users will share there primary SMTP address.
I'm attempting to use:
Get-ADUser -Filter "proxyAddresses -like {$_ -cmatch 'SMTP:'}" | Disable-ADAccount -WhatIf
from a list of emails I only want to disable users where the email and primary SMTP match, however when attempting this as shown above I get 0 matches.
As soon as I use the regex above I get no matches however If I use *$_*
I will get matches from multiple different users with the same secondary proxy addresses.
Any advice on how I can move forward/ a better angle to come at this issue from would be greatly appreciated.
I'm now coming at this from a more sensible position I'm now using
Get-aduser test -properties proxyaddresses | %{$_.proxyaddresses}|?{$_ -cmatch 'SMTP:'}
and am going to create a loop along the lines of...
get ad user from smtp
if aduser primary SMTP is a match to current email then move and disable ad account
else display warning about duplicate smtp
endif