We are moving a site collection from one web app to another, so the host header is changing. Many of the SharePoint links automatically update with the new URL, but we have thousands of documents of various types (.docx, .pptx, .js, .xsn, etc.) in libraries across the site collection that have static links pointing to references elsewhere in the site collection. I'd like to use PowerShell to iterate through the entire site collection, find all documents that have the old host header in a link, and replace it with the new host header. I've got to believe others have encountered this same problem and written PS code to solve it, and hoping someone can share a PS file that worked for this task. Thanks much.
You don't mention the version of SharePoint but since you're talking about different webapps I can safely assume this is on-premises. It does appear to be possible to open a document and search text inside it, though I freely admit I have not tried a method myself to verify you can wrap SharePoint around this but it should be possible. Since there's many examples of how to loop through all documents in a site collection I won't bother with that here, but I would try reviewing this example on a single document in a library to see if it works. If so, wrap that code in foreach loops (filtering out lists using like (if $list.basetemplate -eq "DocumentLibrary") and other necessary steps.
Depending on your issue, this issue shouldn't be that bad if you have SharePoint 2016 or higher with Office Online Server, and use the durable link instead of the actual physical link.