Out of memory error for AD query
hi,
i wrote script fetch information ad computers, when running entire domain using full memory , cashing. have options to reduce memory utilization, or how can re-write ?
get-adcomputer -properties * -searchbase "dc=xx,dc=xx,dc=xxxx,dc=xxx `
-filter {objectclass -like "computer" -and operatingsystem -notlike "*server*"} `
|where {($_.passwordlastset) -gt (get-date).adddays(-365)} `
| select-object @{expression={$_.cn};label='systemname'},lastlogondate,operatingsystem,passwordlastset,ipv4address,enabled,distinguishedname `
| export-csv c:\scripts\ad-domaincomputers.csv -notypeinformation -force
tojo
hi tojo,
there 2 things lower memory consumtion of query drastically.
1. try filter as possible in query.
query computers ad , remove havent changed password during last year. filtering in query filtering on attribute pwdlastset.
2. limit amount of properites retreived each object.
query each , every attribute of each computer , discard of them, specify properties want instead of using -properties *.
i recommend trying this:
$filterdate = ((get-date).adddays(-365)).tofiletime() get-adcomputer -filter { operatingsystem -notlike "*server*" -and pwdlastset -gt $filterdate } -properties cn, lastlogondate, operatingsystem, passwordlastset, ipv4address, lastlogontimestamp | select-object @{ expression={$_.cn}; label='systemname'}, lastlogondate, @{expression={ [datetime]::fromfiletime($_.lastlogontimestamp) }; label='lastlogontimestamp'}, operatingsystem, passwordlastset, ipv4address, enabled, distinguishedname | export-csv c:\scripts\ad-domaincomputers.csv -notypeinformation -force
Windows Server > Windows PowerShell
Comments
Post a Comment