PowerTip: Encrypt Files with PowerShell

Summary: Learn how to easily encrypt files by using Windows PowerShell.

Hey, Scripting Guy! Question How can I use Windows PowerShell to easily encrypt files?

Hey, Scripting Guy! Answer Use the Encrypt static method from the System.IO.File .NET Framework class, for example:


Comments (3)

  1. Keith Garner says:

    Great idea. However, most people should never use this function.
    The files can only be decrypted by the same user on the local machine. If you move the encrypted files to another machine your files will be unrecoverable.

  2. Steve says:

    What about Zipping a file?

  3. Norton says:

    Actually…you can do it, it’s just a bit tricky.

    The file is encrypted using DPAPI. The key (or DPAPI Blob) is stored in the user’s Master Key File in Windows. That file is encrypted using the user’s password (local or domain).

    So, technically you can migrate the encrypted file to another machine IF you use the same credentials on the new machine AND you backup and restore the user’s Master Key File.

Skip to main content