In the SharePoint server, you have to use GetListItem($FileURL)
to check if a file exists in a SharePoint document library without looping using PowerShell
Script
$siteURL = "SiteURL" #provide the site url
$FileURL = "DocumentURL" #provide the document URL
try{
$Found = (Get-SPWeb $siteURL).GetListItem($FileURL)
#if the file exists return the file name
If ($Found -ne $null){
write-host "The file $($Found.Name) is found"}
}
#if file not found, it will raise an error, so we use try-catch
catch{ write-host "The file is not found"}
Output