Powershell Script: Validate if Computer account exists in Active Directory

The below script will let you quickly validate if given computers are exists in Active Directory. You have to keep both script and Computer.txt in same location. Add the computer netbios name in text file separated by new line. The result will be saved in Output.csv file in script folder.

$File = "$PSScriptRoot\Computers.txt" 
$LogFile = "$PSScriptRoot\Output.csv" 
# Function to WriteLog File 
Function WriteLog($Msg) 

    $Text = $Msg 
    Add-Content -Path $LogFile  $text  
    Write-Host $Text 

$ComputerList = Get-Content -Path $File 
$TotalRecord = ($ComputerList).Count 
foreach ($computer in $ComputerList){ 
    try{$ADComputer = Get-ADComputer $computer -Properties *} 
    catch{ WriteLog "$computer,Does not Exists in AD"} 
    if (!$error) {  WriteLog "$computer,Computer exists in AD"} 

Related Posts:

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top