So basically, I have a script that can generate a list of all the users in Active Directory, with their lastlogondate, samaccountname and name. However, I want to add a new clause to this where it EXCLUDES disabled (users). There doesn't seem to be an object such as disabledUsers that I could just add to the end of my Where-Object part.
So because there is no object ID for disabled users, I understand that it should be something like this:
$userList = Get-ADuser -filter {Enabled -eq $True}
But I keep running in to syntax errors when I add this
$companyName = "GG"
$dateStr = (Get-Date).ToString("yyyyMMdd-hhmmss")
$exportPath = "C:\"
$exportFileName = "$($exportPath)\($dateStr)_($companyName)_userlist.csv"
$userList = Get-ADUser -Filter "*" | Where-Object {($_.DistinguishedName -notLike "*System*")} | Select-Object Name,samAccountName, lastLogonDate
$userList | Export-Csv -Path $exportFilename -NoTypeInformation
I would very much appreciate some assistance here friends.