Hey guys,
I read through a ton of posts between here and China and I just can't seem to figure this out.
I'm running the below script to check my computers which is a simple txt file with computer names in order to export information to another TXT file to tell me if the PC exists in Active Directory or not. I have tried the $erroractionprefference which just supresses the error and doesn't include non existing PCs. All I get is a list of existing PCs however I need the non existent PCs so I can purge my ticketing system.
Import-Module Activedirectory
$computers = Get-Content C:\Users\healdk\Desktop\ZebraPC.txt
ForEach ($computers in $computers)
{
if ((Get-ADComputer $computers)-eq $null) {Write-output"$computers | IT'S NOT THERE DUDE"}
else {Write-output"$computers | IT'S THERE DUDE" | Out-File"C:\Users\healdk\Desktop\PCExists.txt"}