PowerShell - finding users who are Inactive AND not disabled

25,253

Solution 1

Filter it the other way?:

Search-ADAccount -UsersOnly -AccountInactive -TimeSpan 30.00:00:00 |where {$_.enabled}

Solution 2

The Search-ADAccount does not accept a parameter -Filter. Please see the Technet docs or Get-Help Search-ADAccount for a list of supported parameters.

You can pipe the results of the search to Where-Object to get only enabled users:

Search-ADAccount -UsersOnly -SearchBase "ou=FirstOU,dc=domain,dc=com" -AccountInactive -TimeSpan 30 |
    Where-Object { $_.Enabled -eq $true }
Share:
25,253

Related videos on Youtube

Npv23g
Author by

Npv23g

:0XXk' .. o0x. ckd' 'oO0000xxxO00xl,. .. :NMMX: .. .xWK. 'XMNd .,XMWd.. ..dNMWK,.. 'XXWMWO' .. dWK. .'.. . .KMWo. ;XMMX. ;Xd,OWMXc ... oWK. .. .. .KMWo. .KMMX. .. . :Nx .lXMM0; . .oW0. .:ldOOc. .:lxOOc;lx0XO; .KMWo. :NMX: .cdk0KKkc. . ,lkO0000x. cNO .kWMNo. .lNO .;NMWd. .:NMW0c;;OWNd. .KMWo....;dXXo. ,0Nx,. ,0MWO. kWWo. .oX, lW0. cXMMK: cNk .NMWd. .NMNl. .'. .KMWo,ldl::. ;XWO'....dNMX. .KMW0l.. ,... oWK. .dWMWd.;Xx. .NMWd. .NMNl. .KMWo. 0MWKdllc::::, ,kXWMWW0d,. . oWK. ;0MMXkNo .NMWd .NMNl .KMWo. 0MMK' . ..;o0WMWO. oWK. .oNMMNc .NMWo .NMNl .KMWo ,XMMKc.. .. 'xKo ;XMX. .xWK ,OWNl .XMNo .XMNc .KMWo 'xXWMWKOkxdd; .kNWOlco0Kk, ... ... .... ... .... ..',,... ..,;,..

Updated on September 18, 2022

Comments

  • Npv23g
    Npv23g almost 2 years

    I wrote this cmdlet:

    Search-ADAccount -filter {(enabled -eq $true)} -Users Only -SearchBase "ou=FirstOU,dc=domain,dc=com" -AccountInactive -TimeSpan 30
    

    But it outputs an error:

    Search-ADAccount : A parameter cannot be found that matches parameter name 'fil
    ter'.
    At line:1 char:25
    + Search-ADAccount -filter <<<<  {(enabled -eq $true)} -UsersOnly -SearchBase "
    ou=FirstOU,dc=domain,dc=com" -AccountInactive -TimeSpan 30
        + CategoryInfo          : InvalidArgument: (:) [Search-ADAccount], Paramet
       erBindingException
        + FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.ActiveDirectory
       .Management.Commands.SearchADAccountCmdlet
    

    Could someone please help?