Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

Checking User in AD

$
0
0

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}

======================   


Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>