Quantcast
Channel: Directory Services forum
Viewing all articles
Browse latest Browse all 31638

PasswordNeverExpires

$
0
0

Hello,

I am trying to create a script for auditing purposes. For ease of use, I would like all the information in the same script, but I am strugling with PasswordNeverExpires property of the users object. Everything else works like a charm. Can anyone tell me why the underlined code does not output True or False?

$NumDays = 0
 $LogDir = ".\Users-Last-Logon.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=4000

 $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={$_.properties.description};n='Description'},`
 @{e={$_.properties.passwordneverexpires};n='PW'},`
 @{e={[string]$adspath=$_.properties.adspath;$account=[ADSI]$adspath;$account.psbase.invokeget('AccountDisabled')};n='Account Is Disabled'}

 $users | Export-CSV -NoType $LogDir



Viewing all articles
Browse latest Browse all 31638

Trending Articles



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