0

Working to get all active users in AD (LastlogonTimestamp within 14 days): That puts the result in Array - $ADActiveUsers

$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
Result Looks like: Name | SamAccountName | LastLogonDate | employeeType | UserPrincipalName | E-mailAddress |

*** SQL Query in Array.

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

Result looks like: SAMAccountName "James.Bond"

***Where i`m stuck: I need to be able to compare the SQL Array Result to the Active Directory Array result and create an Array for that (Email Array)

**End Result - I`m trying to create an E-mail notification from the Email Array (Result)

Kross
  • 1
  • 1
  • It's not simple to create exact code for your question. here is approximate solution $ADActiveUserts | ForEach {$SqlData = Invoke-Sqlcmd -Query "select NT_LGN_TXT from vw9897 where SCU_QUE_CD is Null and WhatEverColumn = '$_.SamAccountName'" -ServerInstance (Server Name) -Database (DB Name)} – Daniel N Dec 06 '18 at 23:42
  • As an aside: It's best to [avoid the use of script blocks (`{ ... }`) as `-Filter` arguments](https://stackoverflow.com/a/44184818/45375). – mklement0 Dec 07 '18 at 03:38

0 Answers0