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

How to check a list of users against AD if they exist

$
0
0

Hi Scripting Guys,

I have a powershell script that allows me to query a list of users against AD, and if they exist, it will write their details into a new file.

I want to adapt this script so that it will still do the same, but if the user does NOT exist anymore, write a line such as "<User-ID> does not exist in AD".

Here's the code I have so far:

Import-Module ActiveDirectory
$UserList = get-content C:\temp\checkAD\Accounts.txt
Foreach ($Item in $UserList) {
Get-aduser -filter {samAccountName -eq $Item} | Out-File C:\temp\checkAD\existingAccounts.txt -encoding default -append
}

Does anybody know how to achieve that?

Thanks and best regards,

Cap'



Viewing all articles
Browse latest Browse all 15028

Trending Articles



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