Powershell command Export Disabled Computers

Boopathi S 3,806 Reputation points
2021-11-24T18:37:00.02+00:00

Hello,

I am using the below command to export Computers which are Disabled.

Get-ADComputer -Filter {LastLogonTimeStamp -lt $time} -ResultPageSize 2000 -resultSetSize $null -Properties Name, OperatingSystem, SamAccountName, DistinguishedName

But it returns all the Computers instead of only Disabled Computers.
152297-capture.jpg

Please help to correct the powershell command.

Windows for business Windows Server User experience PowerShell
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Rich Matheisen 47,901 Reputation points
    2021-11-24T19:45:14.72+00:00

    The -Filter parameter takes a string argument, not a script block. And, since you looking for disabled computer objects, you have to check the "Enabled" property.

    Try this as the filter string:

    "LastLogonTimeStamp -lt $time -and Enabled -eq 'false'"
    

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.