Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Wednesday, May 22, 2013 6:57 PM
I found the following script on a PowerShell repository, and it works great. I just need to increase the size limit, since it's limited to 1000 entries. I need to put in -sl 0 or something to that effect, but I'm not sure where. Here is the code:
$NumDays = 0
$LogDir = "c:\User-Accounts.csv"
$currentDate = [System.DateTime]::Now
$currentDateUtc = $currentDate.ToUniversalTime()
$lltstamplimit = $currentDateUtc.AddDays(- $NumDays)
$lltIntLimit = $lltstampLimit.ToFileTime()
$adobjroot = [adsi]''
$objstalesearcher = New-Object System.DirectoryServices.DirectorySearcher($adobjroot)
$objstalesearcher.filter = "(&(objectCategory=person)(objectClass=user)(lastLogonTimeStamp<=" + $lltIntLimit + "))"
$users = $objstalesearcher.findall() | select `
@{e={$_.properties.cn};n='Display Name'},`
@{e={$_.properties.samaccountname};n='Username'},`
@{e={[datetime]::FromFileTimeUtc([int64]$_.properties.lastlogontimestamp[0])};n='Last Logon'},`
@{e={[string]$adspath=$_.properties.adspath;$account=[ADSI]$adspath;$account.psbase.invokeget('AccountDisabled')};n='Account Is Disabled'}
$users | Export-CSV -NoType $LogDir
All replies (5)
Wednesday, May 22, 2013 7:05 PM âś…Answered
Adjust the pagesize to something like 1000 to get everything.
$objstalesearcher.pagesize=1000
Boe Prox
Blog | PoshWSUS | PoshPAIG | PoshChat
Wednesday, May 22, 2013 7:24 PM
If PageSize is not defined, your query is limited to 1000 records. Assigning any value for PageSize means there is no limit, but records are retrieved in pages. The most efficient value depends on many factors (I assume). In my test domain with about 3000 users I find 200 is optimal, but it doesn't matter much.
Richard Mueller - MVP Directory Services
Nice explanation!
Boe Prox
Blog | PoshWSUS | PoshPAIG | PoshChat
Tuesday, July 16, 2013 10:54 AM
Just i want to know - where we need to $objstalesearcher.pagesize=5000 or more to get full ad details
Wednesday, September 11, 2013 2:19 PM
try this i put it as 25000 , you can change the value...
$NumDays = 0
$LogDir = "c:\User-Accounts.csv"
$currentDate = [System.DateTime]::Now
$currentDateUtc = $currentDate.ToUniversalTime()
$lltstamplimit = $currentDateUtc.AddDays(- $NumDays)
$lltIntLimit = $lltstampLimit.ToFileTime()
$adobjroot = [adsi]''
$objstalesearcher = New-Object System.DirectoryServices.DirectorySearcher($adobjroot)
$objstalesearcher.filter = "(&(objectCategory=person)(objectClass=user)(lastLogonTimeStamp<=" + $lltIntLimit + "))"
$objstalesearcher.PageSize=25000
$users = $objstalesearcher.findall() | select `
@{e={$_.properties.cn};n='Display Name'},`
@{e={$_.properties.samaccountname};n='Username'},`
@{e={[datetime]::FromFileTimeUtc([int64]$_.properties.lastlogontimestamp[0])};n='Last Logon'},`
@{e={[string]$adspath=$_.properties.adspath;$account=[ADSI]$adspath;$account.psbase.invokeget('AccountDisabled')};n='Account Is Disabled'}
$users | Export-CSV -NoType $LogDir
Friday, October 4, 2013 7:44 AM
hello Jod- did you get the solution of this issue.