Reputation: 13
The purpose of this script is to pull all employee IDs from AD, then check them against all employee IDs in SQL. Every employee ID that does not exist in SQL is the intended output.
import-module activedirectory
$sqlpeeps = Invoke-Sqlcmd -ServerInstance '192.168.1.1' -Database 'COMPANY' -Query "SELECT EmployeeID FROM [COMPANY].[dbo].[employee] WHERE [COMPANY].[dbo].[employee].[EmployeeStatus] in ('A', 'S', 'L')"
$adpeeps = get-aduser -filter * -searchbase "OU=OU,OU=OU,OU=OU,DC=DC,DC=COM" -properties 'EmployeeID'
$adpeeps | where-object { $_ -notin $sqlpeeps} | out-host
What I have now seems to output all employee IDs
Upvotes: 0
Views: 219
Reputation: 18061
$adpeeps
is a list of AD user objects, but $sqlpeeps
are EmployeeIDs, so change it to:
$adpeeps | Where-Object { $_.EmployeeID -and ($_.EmployeeID -notin $sqlpeeps) }
Upvotes: 1