$Users = GC "Desktop\Master.txt"
foreach ($user in $users) {
$userobj = $(try {Get-ADUser $user} catch {$Null})
If ($userobj -ne $Null) {
Write-Host "$User Exists"
} else {
Write-Host "$User Doesn't Exist"
}}
I am using this code to check if a user exists in AD. Later on this notepad file is processed to delete the users that are on the file. I was going to see if it was possible that I can remove the users off the list that don't exist. Is there a command to remove the line from the Notepad file that has the names on if the user doesn't exist in AD