Refresh sitemap.xml on demand for a small static HTML site with a PowerShell script

Abstract: A short PowerShell script can walk your local HTML folder and write a valid sitemap.xml in seconds, so you can regenerate it after every batch of edits—no installs, subscriptions, or third-party crawls.

Created: 2026-11-21 by

For a hand-maintained site of a dozen or so HTML pages, the most dependable way to keep sitemap.xml current on Windows is a small local script that reads your site folder and writes the file for you. You run it after each round of edits, upload the result, and you are done—no browser tools, no installs, and nothing that needs standing access to your live server.

Picking the right approach for a tiny site

There are three realistic routes, and the best one depends on how often you touch the site:

  • Online generators are fine for a one-off file, but every future edit means visiting the site again, re-entering the URL, and downloading a fresh copy. For a site you update every few weeks, that chore adds up.
  • Desktop crawlers, such as the free tier of Screaming Frog SEO Spider (which handles up to 500 URLs), crawl the live site and can export a sitemap directly. This is the better choice when your published URLs don't resemble your file names—more on that below.
  • A local script reads your files straight off disk, costs nothing, and is trivially repeatable. For roughly 15 pages that rarely change structure, this is usually the sweet spot.

What a useful sitemap.xml actually contains

A sitemap is just an XML list of URLs. The only mandatory element per URL is <loc>. Two details matter in practice:

  • <lastmod> is worth including, but only if it is honest. Deriving it from each file's modification timestamp gives search engines a real signal about what changed. Do not invent dates to make pages look fresh.
  • <priority> and <changefreq> can be skipped entirely—search engines ignore them, so they add noise without value.

The file must also be well-formed XML, which means any & in a URL has to be escaped, and it should be saved as UTF-8 without a byte-order mark so parsers don't choke on the first bytes.

A reusable script you can rerun after every edit

Save the following as make-sitemap.ps1 somewhere outside your site folder so it never gets published by accident, then adjust the three values at the top:

# make-sitemap.ps1
$root = "C:\websites\mysite"       # local copy of the site, no trailing slash
$base = "https://www.example.com"  # live origin, no trailing slash
$skip = @("404.html")              # filenames that should never be listed

$pages = Get-ChildItem $root -Recurse -Filter *.html -File |
         Where-Object { $skip -notcontains $_.Name } |
         Sort-Object FullName

$rows = [System.Collections.Generic.List[string]]::new()
$rows.Add('<?xml version="1.0" encoding="UTF-8"?>')
$rows.Add('<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">')

foreach ($p in $pages) {
    $path = $p.FullName.Substring($root.Length).Replace('\', '/')
    $path = $path -replace '(?i)(^|/)index\.html$', '/'  # index pages become their folder
    $url  = [System.Security.SecurityElement]::Escape("$base$path")
    $mod  = $p.LastWriteTimeUtc.ToString('yyyy-MM-dd')
    $rows.Add("  <url><loc>$url</loc><lastmod>$mod</lastmod></url>")
}

$rows.Add('</urlset>')
[System.IO.File]::WriteAllLines("$root\sitemap.xml", $rows)

The script walks every .html file under the root, skips anything on your exclusion list, converts backslashes to forward slashes, and writes one <url> entry per page. The escape call handles XML-special characters in URLs, and WriteAllLines produces UTF-8 without a BOM. Because the sitemap is written into the site root, it will be overwritten cleanly on the next run.

Running it

Open PowerShell in the folder where you saved the script and run:

powershell -ExecutionPolicy Bypass -File .\make-sitemap.ps1

The Bypass flag only applies to this single invocation, so you don't loosen your machine's script policy permanently.

When local file names don't match live URLs

The script assumes the URL of each page mirrors its path on disk. That breaks in two common situations:

  • Index files. Handled above: index.html maps to the site root and blog/index.html maps to /blog/, which is what visitors and crawlers should see.
  • Clean URLs. If your host rewrites about.html so the public address is just /about, the script's output will disagree with reality. Your options are to keep the .html suffix in your public links, add a small rename rule to the script, or switch to a crawler-based approach: point Screaming Frog's free spider at the deployed site and export its sitemap, which reflects the URLs as they actually resolve.

Whatever you list, make sure every URL returns 200 and is the canonical version—never include pages that redirect or 404.

Publish, register once, then just repeat

After generating the file:

  1. Upload sitemap.xml to your site root.
  2. Add a line Sitemap: https://www.example.com/sitemap.xml to robots.txt so any crawler that reads it can find the file.
  3. Submit the sitemap once in Google Search Console (and Bing Webmaster Tools if you like). This is a one-time registration, not a per-edit ritual.

From then on, your entire maintenance routine is: edit pages, run the script, upload the refreshed file. Search engines revisit on their own schedule; you don't need to resubmit after every change.

Frequently Asked Questions

Do I need <priority> and <changefreq> in my sitemap?

No. Google has stated it ignores both. If your generator adds them, that's harmless, but a hand-rolled file is cleaner without them. An accurate <lastmod> is the only optional field with real value.

How often should I regenerate the file?

Whenever you add, remove, or rename a page, or make a substantial content change you want reflected in <lastmod>. The file doesn't need to be "fresh" for its own sake—it just needs to match reality.

Do I have to resubmit the sitemap in Search Console after every update?

No. One submission is enough; Google re-reads the file periodically. Resubmitting doesn't speed up crawling, so save the clicks.

PowerShell refuses to run my script. What now?

That's the execution policy, not a bug. Launching with -ExecutionPolicy Bypass as shown allows that one run. If you run scripts often, Set-ExecutionPolicy RemoteSigned -Scope CurrentUser is a reasonable standing setting.

Is a sitemap even necessary for a 15-page site?

Strictly, no—a small, well-interlinked site gets crawled without one. But a sitemap speeds up discovery of brand-new pages and gives you a per-URL status view in Search Console, which is genuinely useful for spotting problems.

Can the script handle .htm files or other extensions?

Yes—change the filter to *.htm* (or add a second Get-ChildItem pass) if your site mixes extensions. Just keep file naming consistent, ideally all lowercase, because URLs on Linux-based hosts are case-sensitive even though Windows filenames are not.

Latest News

How to Display Output of xterm Command in Terminal Screen using Cron

Resolve the inability to display xterm output in a terminal screen from cron by redirecting logs or using wall instead of insecure X11 workarounds.

Read More
Expose Local Server on VPS Preserving Real Client IPs (OS Level)

Resolve VPS logging showing only gateway IPs by configuring reverse proxies to forward real client addresses via X-Forwarded-For headers.

Read More
How to Clear Recent Files History in Linux without Deleting Actual Files?

Clear recent files history in Linux by deleting ~/.local/share/recently-used.xbel without removing the actual files.

Read More
Best HDD Copy Strategy: Manually Syncing and Rewriting Scratch

Resolve data drift between two 4TB hard drives by using rsync with the --delete flag to manually sync and rewrite scratch data for an exact mirror.

Read More
Understanding Bash Prompt Abbreviations: An Overview

Resolve repetitive typing errors by creating and persisting Bash aliases in the .bashrc file for improved command-line efficiency.

Read More
Free Tools and Methods to Log Real-Time Performance Details in Task Manager

Log real-time CPU and memory metrics to CSV files using Windows Performance Monitor Data Collector Sets to troubleshoot system slowness.

Read More
Contact Qatar Airways Customer Service: Phone Number, Help Center, and More

Resolve urgent Qatar Airways reservation issues like flight changes and baggage claims using the US phone number +1801-855-5905 or online self-service tools.

Read More
Windows 11: Alt Codes Displaying Wrong Characters - Solutions

Resolve Windows 11 Alt codes showing wrong characters by verifying the US keyboard layout and enabling Num Lock.

Read More
Run Programs with Elevated Privileges: A Comprehensive Guide

Eliminates the need to type sudo for frequent administrative tasks by configuring .bashrc aliases or functions.

Read More
Dynamically Changing Dates in Excel Formulas Using Cells

Eliminate manual date updates in Excel by using cell references to create dynamic formulas that automatically adjust calculations when input dates change.

Read More
Granting Edit Access to a Specific Excel Sheet in an Office 365 User Email ID-Based Login

Excel Online lacks native sheet-level permissions, so users must split workbooks or use worksheet protection to isolate edit access for specific tabs.

Read More
Creating Network Load on Local Wi-Fi from One PC

Generate sustained Wi-Fi bandwidth load from a single PC using a VM SFTP server to test router stability and throughput.

Read More
Changing the Default Editor for Batch Files in Windows 11's File Explorer

Resolve the issue of batch files opening in Notepad by changing the default editor to a preferred application like VS Code.

Read More
Gain WiFi Connection Minutes Before Losing it by Changing MAC Address

Bypass MAC address filtering to restore WiFi connectivity temporarily when a device is blocked by network administrators.

Read More
Photos Folders Turned Black: Troubleshooting Picture Applications on Windows

Resolve black screens in Windows Photos by resetting the app, updating graphics drivers, and repairing system files.

Read More
Troubleshooting High CPU Temperature Values: A Step-by-Step Guide

Resolve high CPU temperatures and thermal throttling by monitoring with Speedfan, cleaning dust from cooling components, and replacing degraded thermal paste.

Read More
Make cURL establish TLS connection with CA unknown

Resolve cURL TLS connection failures with unknown or self-signed certificates by using the --insecure flag to bypass CA validation.

Read More
Troubleshooting Incorrect Network Metrics Values in Grafana, Prometheus, InfluxDB, and Telegraf

Fix incorrect network metrics in Grafana, Prometheus, InfluxDB, and Telegraf by verifying interface selection, resolving unit mismatches, and handling counter resets.

Read More
Start Another Terminal Window (cmd.exe) Windows Repair/Troubleshoot

Provides step-by-step instructions to access the Windows Command Prompt via bootable media for advanced system repair and troubleshooting.

Read More
Thinkpad P1 Gen 6: Sudden Thunderbolt 3 Dock USB-C Charging Stopped Working

Resolve sudden Thunderbolt 3 dock USB-C charging and internet failure on ThinkPad P1 Gen 6 by updating firmware, resetting the dock, and adjusting power settings.

Read More
ASUS Windows 11 Laptop: Internet Connection Issue with Hotspot

Resolve ASUS Windows 11 laptop spinning wheel issue when connecting to mobile hotspot by resetting network stack, disabling IPv6, and adjusting power settings.

Read More
Developing iOS Project with Firebase: Logging in and Sending Push Notifications

Integrates Firebase to enable secure user authentication and push notifications in iOS applications.

Read More
Troubleshooting Bash Script with Suspected Issues of Spaces, Dashes, Filenames and Quoting

Resolve Bash script failures caused by word splitting, globbing, and special characters in filenames by applying proper quoting techniques.

Read More
Populating OneDrive Folder for Local Backup without Affecting Remote Files

Prevent OneDrive from deleting remote files during Windows reinstallation by unlinking the account or using symbolic links to isolate local data.

Read More
Force First Frame as Keyframe Without Re-encoding: A Quick Solution

Resolve inaccurate seeking and playback glitches by re-encoding video to ensure the first frame is a valid keyframe.

Read More
Find Information in Database Using WSL (Ubuntu) on Windows-10

Resolve database connection issues from WSL Ubuntu on Windows 10 by configuring client tools and network access to query remote or local servers.

Read More
Configuring a New Router with Different Networks: One Family, One Guest

Resolve IP conflicts and isolate guest traffic by configuring a second router with a distinct subnet via its WAN port.

Read More
Quickly Open Multiple Stock Websites with a Single Command

Solve the problem of manually opening multiple stock research websites by creating a single command to launch them simultaneously on Windows, macOS, or Linux.

Read More
Improved Adobe Acrobat Search Experience: Access Advanced Search with Ease

Access advanced search filters like case sensitivity and regex in Adobe Acrobat by clicking More Options in the Find bar.

Read More
Port Forwarding VM via OpenVPN: A Comprehensive Guide

Configure OpenVPN server and iptables to forward specific ports from VPN clients to a virtual machine's internal IP address.

Read More
Understanding Partitions in the 1980s: A Look Back at MS-DOS and Master Boot Record

Explains how the Master Boot Record and partition table enabled MS-DOS to manage multiple disk volumes on a single physical drive.

Read More
Windows 10 Enterprise: Keyboard Not Detected in Managed Organization with Admin Privileges

Resolve Windows 10 Enterprise keyboard detection failures caused by Group Policy restrictions, driver corruption, or USB enumeration errors.

Read More
Can't Find x86_64 Versions of Applications on MacOS arm64 (M1)

Resolve missing x86_64 app issues on M1 Macs by installing Rosetta 2 and reinstalling apps as universal binaries.

Read More
How to Hide Installation Source for an Android App

Manage Android app installation source visibility by using USB transfers or file managers to reduce browser traces and isolate data via work profiles.

Read More
Connecting Momentus 4200.2 ST9808210A Hard Drive via USB Cable

Resolve inability to access Seagate Momentus 4200.2 ST9808210A hard drive by connecting it via USB using a compatible SATA-to-USB adapter and configuring the disk in Windows.

Read More