Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

We're in the process of converting an HTML help system to a SharePoint document library. We have about 3000 individual HTML documents that we're converting to Word. About 20% of the documents include hyperlinks to related documents, and they're all relative links.

We're trying to automate the process of parsing each document, and in any instance where we have a hyperlink, replacing the last three bytes of the string--"htm"--with "doc".

I've seen some PowerShell samples where people are parsing documents (usually server logs) looking for specific bits of info, but have not been able to find anything about replacing specific characters in a file before closing/saving it.

Does anyone have any tips to achieve this with PowerShell? or ideas about more appropriate tools?

share|improve this question
up vote 2 down vote accepted

Simply open the file, replace "htm" to "doc" then save and close this file:

Get-ChildItem -Path . -Recurse | 
Where-Object {-not $_.PSIsContainer} | 
Foreach-Object { 
    (Get-Content $_) -replace "htm", "doc" | Set-Content $_
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.