0

Can you help me with this oneliner? I've tried a different syntax, but to no avail. I want to find all user accounts that have one specific manager and the manager needs to be specified by mail.

Get-ADUser -Filter {manager -eq ((Get-ADUser -Filter {mail -eq "name@company.com"}).DistinguishedName)} -Properties AccountExpirationDate | select samaccountname, AccountExpirationDate

Adam.

Adam
  • 5
  • 2

3 Answers3

0

This one should work :

Get-ADUser -Filter "manager -eq `"$((Get-ADUser -Filter `"mail -eq 'name@company.com'`").DistinguishedName)`"" -Properties AccountExpirationDate | select samaccountname, AccountExpirationDate

I prefer double quotes for Filter parameter. The equal test need to be passed as a string. So, you need to escape the double quote inside the main filter.

CFou
  • 978
  • 3
  • 13
0

There might be more elegant ways of solving this but the following should work.

Edit after you added more info.

I assume you want all the "service accounts" under that manager and not that the manager itself is assumed to be a service account?

Get-ADUser -Filter "manager -eq '$($(Get-ADUser -Filter 'mail -eq "name@company.com"').DistinguishedName)' -and extensionAttribute8 -eq 'service account'" -Properties AccountExpirationDate | select SamAccountName, AccountExpirationDate

Furthermore - mklement0 has an excellent answer with quite extensive information on the Filter-parameter and how it ought to be used, despite the ActiveDirectory module allowing for a different approach.

notjustme
  • 2,376
  • 2
  • 20
  • 27
0

Both answers works, I am sorry but I need to change a desired commend:

as i changed your commands they look like

Get-ADUser -Filter "manager -eq `"$((Get-ADUser -Filter `"mail -eq 'name@company.com'` -and extensionattribut8 -eq "service account"").DistinguishedName)`"" -Properties AccountExpirationDate | select samaccountname, AccountExpirationDate

Get-ADUser -Filter "manager -eq '$($(Get-ADUser -Filter 'mail -eq "name@company.com" -and extensionattribut8 -eq "service account"").DistinguishedName')" -Properties AccountExpirationDate | select SamAccountName, AccountExpirationDate

and it doesn't work. Get i get more of your help? Changed: 2 conditions is the filter.

Adam
  • 5
  • 2
  • See my updated answer. Also, you should remove this answer and instead add the new info in your original question. – notjustme Nov 05 '20 at 14:39