Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Need help in tweaking the Powershell AD query to find inactive computers

$
0
0

Hello All,

I am a beginner in powershell. i managed to construct a query to find out the inactive computers with last logon name. but the problem is that query time out everytime. if i limit the scope to an OU with less no of systems, then we get to see the results. (eg; from 10k machines to 3k machines)....

is there any way to fine tune this query so that i can run it against all machines in AD .. say around 80k....

import-module Activedirectory
$DaysInactive = 60
$time = (Get-Date).Adddays(-($DaysInactive))
Get-ADComputer -SearchBase "ou=a,DC=x,DC=y,DC=z"  -Filter {(lastLogonTimestamp -lt $time) -and (operatingsystem -notlike '*server*') -and (operatingsystem -notlike "*embedded*")  } -Properties LastLogonDate,operatingsystem | select Name,LastLogonDate,operatingsystem,distinguishedname



JG


Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>