0

I have the following Code - to get all active users in AD (LastlogonTimestamp within 14 days):

$ADActiveUsers = Get-ADUser -Filter {(employeeType -like "*user*") -and (enabled -eq $true)} -Properties lastlogondate, employeetype, emailaddress |
    ? { ($_.LastLogonDate -gt (Get-Date).AddDays(-15))} |
    Select-Object Name, SAMAccountName, LastLogonDate, employeetype, userprincipalname, emailaddress

Also, I'm trying to get all users that haven't completed their security questions and answers with this query:

$SqlData = Invoke-Sqlcmd -Query "select NT_LGN_TXT from vw6201 where SCU_QUE_CD is Null" -ServerInstance (Server Name) -Database (DB Name)

My need (where I'm stuck) - I'm trying to compare the data from SQL to the AD, create array for the result and send it as e-mail notification.

Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
Kross
  • 1
  • 1
  • As an aside: It's best to [avoid the use of script blocks (`{ ... }`) as `-Filter` arguments](https://stackoverflow.com/a/44184818/45375). – mklement0 Dec 06 '18 at 03:22
  • It would be very helpful if you can show us some of the results you get in `$SqlData`. Fake real nbames and addresses of course. – Theo Dec 06 '18 at 11:42
  • Hello, SQL Result "NT_LGN_TXT" = James.Bond (example) $ADActiveUsers Result = Name | SamAccountName | LastLogonDate | employeeType | UserPrincipalName | E-mailAddress | I now need to be able to compare the $sqlData and $ADActiveUsers Result - create array for the result and send e-mail – Kross Dec 06 '18 at 20:17
  • Ok, so the `$SqlData` is an array of user names like `James.Bond`. Is that name (with the dot in between) comparable with any of the user properties you get from AD ? It (doesn't look like a proper AD `Name`, `SAMAccountName`, `LastLogonDate`, `employeetype`, `userprincipalname`, `emailaddress` to me..) – Theo Dec 07 '18 at 15:36

0 Answers0