You don't need to use ADSI, that's the old way. Well, you can, but just saying.
Use the PowerShell AD cmdlets?
# Get parameters, examples, full and Online help for a cmdlet or function
(Get-Command -Name Get-ADUser).Parameters
Get-help -Name Get-ADUser -Examples
Get-help -Name Get-ADUser -Full
Get-help -Name Get-ADUser -Online
(Get-Command -Name Get-ADComputer).Parameters
Get-help -Name Get-ADComputer -Examples
Get-help -Name Get-ADComputer -Full
Get-help -Name Get-ADComputer -Online
That is why they exist. Now you need to either download and install or just install the Windows RSAT tools on your workstation...
https://support.microsoft.com/en-us/help/2693643/remote-server-administration-tools-rsat-for-windows-operating-systems
... or remote to a domain controller to use the AD cmdlets.
How To Use The 2012 Active Directory PowerShell Cmdlets From Windows 7
https://blogs.technet.microsoft.com/ashleymcglone/2013/06/27/how-to-use-the-2012-active-directory-powershell-cmdlets-from-windows-7
Then just do something like this...
$Users = 'TestUser001','TestUser001','TestUser001'
ForEach($User in $Users)
{
$User = $(try {Get-ADUser 'TestUser001'} catch {$null})
if ($User -ne $null) {
# Exists
} else {
# Doesn't Exist
Write-Warning -Message "User $User not found"
}
}
$Computers = 'Computer001','Computer001','Computer001'
ForEach ($Computer in $Computers)
{
$Computer = $(try {Get-ADUser 'TestUser001'} catch {$null})
if ($Computer -ne $null) {
# Exists
} else {
# Doesn't Exist
Write-Warning -Message "Computer $Computer not found"
}
}