Using PowerShell executed from a SharePoint Web Server:
$wacoll = get-spwebapplication
foreach($wa in $wacoll){
if($wa.IsAdministrationWebApplication -eq $false){
foreach($site in $wa.Sites){
foreach($web in $site.AllWebs){
# your code here
$web.Dispose()
}
$site.Dispose()
}
}
}