0

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.

  • Post the full error description you're getting – scottwtang Aug 04 '22 at 02:06
  • `Get-ADUser` does not by default return a `LastLogonDate` property, so you need to ask for that using the `-Properties` parameter. Also, you try to save the file onto the root of the C:\ drive, but this is not always allowed. Make sure you can write files there first. – Theo Aug 04 '22 at 11:30

0 Answers0