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!

2
  • 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. Commented Feb 4, 2016 at 13:52
  • Instead of using -notcontains, I have switched to -notmatch and this has done the trick for me. Commented Feb 8, 2016 at 13:38

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.