I have a text file containing 100 server names. I would like to push these into a script and test wheather the computer object exists or if it has been decommissioned (deleted). From the results i can update a tracking sheet that has been left to the side for sometime.
Seems easy enough but i am having problems all day! Below is what i have so far..
Function check-server-object {
$serverlist = get-content "e:\serverlist.txt"
try
{
write-host "#################################"
write-host "Attempting to find computer"
write-host "#################################"
ForEach ($server in $serverlist){
#$tempVar = Get-ADComputer $server
if (Get-ADObject $server -eq $null) { Write-Host "not there"} else {Write-Host "$Server Found In AD!"}
}
}
catch {write-host "$server does not exist" -ForegroundColor Red}
}
check-server-object
I have the try & catch because i was having issues with errors etc.. little bit of a bodge. :/ any anyway so far it only gives me the result of the first server name in the text file... only another 99 to go!! why is it not giving me all the servers ?
Please can you help / explain on the logic and provide any solution to my problem.
Thanks,
Phil