0

I am writing up a script to generate a list of inactive users at both of our office locations. Some of these inactive users will be on Maternity leave, so we put the keyword "Maternity" in their AD description field. I would like for the script to EXCLUDE anyone with that keyword from the report, but I appear to be having issues with piping the info around correctly.

Search-ADAccount -UsersOnly -SearchBase $LondonOU -AccountInactive -TimeSpan 90.00:00:00 | Get-ADUser -Filter * -Properties Description | where {($_.enabled -eq $false) -and ($_.description -notcontains "Maternity")} | Sort LastLogonDate |

The above is what I am using now and it works for showing me the inactive users. I just cannot get it to exclude the Maternity keyword users.

Thank you!

Macky
  • 1
  • 2
    Try replacing `$_.description -notcontains "Maternity"` with `$_.description -notlike "*Maternity*"`. `contains` is for collections mostly and requires complete match and maybe you have spaces or something in your AD field. – beatcracker Feb 04 '16 at 13:52
  • Instead of using `-notcontains`, I have switched to `-notmatch` and this has done the trick for me. – Macky Feb 08 '16 at 13:38

0 Answers0