Hi Scripting Guys,
I am working on a script to automate a task, for that I created one function to check if a user exists in AD before executing the mail function, below is the code, but it seems that it is not working, could
someone please help in this
===========
Function User_Check ()
{
$List = @()
$Users = Import-Csv -Path $FileName
Foreach ($USer in $Users)
{
$User_Check = Get-ADUser -LDAPFilter "(sAMAccountName= $User.sAMAccountName)" -ErrorAction SilentlyContinue
If ($User_Check -eq $Null) {$List += $User}
}
if (($List).count -gt 1 )
{Write-Host -ForegroundColor RED "Below Users already exist in AD $List"}
else {Mail_Function}
======================