Skip to content

Instantly share code, notes, and snippets.

@ZSendokame
Last active January 15, 2026 01:20
Show Gist options
  • Select an option

  • Save ZSendokame/88d0a720a017a9933cabd2e2537ac17a to your computer and use it in GitHub Desktop.

Select an option

Save ZSendokame/88d0a720a017a9933cabd2e2537ac17a to your computer and use it in GitHub Desktop.
Rename all files on two depths to their MD5 hash and remove the originals.
$path = $args[0]
$files = (Get-ChildItem $path -File)
foreach($file in $files){
$extension = $file.Extension
$newName = (Get-FileHash -LiteralPath $file.FullName -Algorithm MD5).Hash.toLower()
$directory = $file.Directory.FullName
$newPath = "$directory\$newName$extension"
if(-not ($file.FullName -eq $newPath)){
Move-Item -Force -LiteralPath $file.FullName -Destination $newPath
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment