Generate a .md5 file for every file in a folder

Hello, I am a newbie using powershell, I am using Get-filehash cmdlet in order to obtain the hash of all .pst files of a directory and I would like to generate a .md5 file for every file/hash, any idea of how to do this?

Something like this?

$files = Get-childitem -Path C:\Temp -Include "*.pst"

Foreach ($file in $files)
    $hash = (Get-FileHash -Path $file.fullname -Algorithm MD5).hash
    Add-Content -Path ($file.fullname + '.md5') -Value $hash

Exactly like that, thank your solution Stefan. I am trying to put together a script that take all exchange users inactive older than 6 months and for each one:

  • Export mailbox to .pst file
    After validate that export complete sucessfully
  • Calculate a hash to that .pst file
  • Remove the mailbox from exchange
  • Remove the user from Active Directory

So I am trying to put the pieces together in one script, so I may comeback to ask for some help in the future.