How can I get these properties for a user via ADSI LDAP, these are the properties from Get-ADUser
, I need the equivalent for ADSI.
- Enabled
- PasswordNeverExpires
- PasswordExpired
- Name
- SamAccountName
- PasswordLastSet
My objective is to query the entire domain for all users and get these attributes.
I tried with the Get-ADUser
cmdlet and it timed out when querying for the users.
Get-ADUser -Filter * -Properties enabled,PasswordNeverExpires,passwordexpired,Name,SamAccountName,mail,passwordlastset -server sc |
where {$_.Enabled -eq "True"} |
where { $_.PasswordNeverExpires -eq $false } |
where { $_.passwordexpired -eq $false } |
Select Name,SamAccountName,mail,
@{l='PasswordExpires';e={$_.passwordlastset+(Get-ADDefaultDomainPasswordPolicy).MaxPasswordAge}},
@{l='DaystoExpire';e={(New-TimeSpan -Start (get-date) -end ($_.passwordlastset+(Get-ADDefaultDomainPasswordPolicy).MaxPasswordAge)).days}}
The above command works on a couple of users but if I query a large set of users it gives invalid enumeration context.