Standardize names while keeping extensions, paths, and collision risks under control.

Sheet: 09 of 25 | Platform: Windows 10/11 | Shell: PowerShell 7.x and Windows PowerShell 5.1 (unless marked otherwise) | Editorial review: November 24, 2026

PowerShell cheat sheet index

Examples use the MGU project root and illustrative staging, backup, and download paths. Replace them with existing, approved paths as needed. Unless explicitly marked as a continuation, examples are independent. Read commands before running them; commands that write or modify files can change existing data.

Quick commands

1. Preview renaming one file

Rename-Item -LiteralPath 'C:\MGU\library\old-name.html' -NewName 'new-name.html' -WhatIf

2. Preview renaming a directory

Rename-Item -LiteralPath 'C:\MGU\library\old-folder' -NewName 'new-folder' -WhatIf

3. Build a lowercase filename mapping

Get-ChildItem -LiteralPath 'C:\MGU-Staging' -File |
    Select-Object FullName, @{Name='NewName';Expression={$_.Name.ToLowerInvariant()}}

4. Preview replacing spaces with hyphens

Get-ChildItem -LiteralPath 'C:\MGU-Staging' -File |
    Where-Object { $_.BaseName -like '* *' } |
    ForEach-Object {
        $new = ($_.BaseName -replace ' +','-') + $_.Extension
        Rename-Item -LiteralPath $_.FullName -NewName $new -WhatIf
    }

5. Detect collisions in a proposed mapping

Get-ChildItem -LiteralPath 'C:\MGU-Staging' -File |
    Group-Object { ($_.BaseName -replace ' +','-').ToLowerInvariant() + $_.Extension.ToLowerInvariant() } |
    Where-Object { $_.Count -gt 1 }

Operational notes

Rename-Item changes names, not parent locations. Case-only renames can require an intermediate name on Windows. Check for collisions, update affected public URLs and references, and use source control or backups before executing.

Official documentation