Trust Services Encrypt Files Powershell Sample

Trust Services Encrypt Files Powershell Sample


Sample PowerShell script FileEncrypt.ps1 shows the very basic usage of Trust Services to encrypt and decrypt data from the files.

The sample uses a single certificate for Policy Administrator, Data Publisher and Data Consumer roles. This sample also uses a single Data Policy that dictates encryption for all files.


Prerequisites are the same as in Getting Started Tutorial and other Trust Services samples.


To download FileEncrypt.ps1 sample script, visit Trust Services Samples Download page and click on "EncryptFilesPS".

Steps to run the script

  1. This script requires the following information:
    1. Thumbprint of X509 certificate stored in Current User Windows Certificate Store, and
    2. Trust Server name.
    See Steps 1 and 2 in Getting Started Tutorial on how to create X509 certificate, create Trust Server using Trust Services Portal, and upload created X509 certificate to Trust Server.
  2. Start Trust Services Shell shortcut in Start Menu.
  3. Run downloaded script as follows to encrypt a folder:
    .\FileEncrypt.ps1 -certificateThumbprint CBD98CE6C208125E164F4A4F125BAD7B3DE0D9E3 -trustServerName wpccyexb2e -inputDirectory G:\test\Clear -outputDirectory G:\test\Encrypted -encrypt 1
    To decrypt a folder:
    .\FileEncrypt.ps1 -certificateThumbprint CBD98CE6C208125E164F4A4F125BAD7B3DE0D9E3 -trustServerName wpccyexb2e -inputDirectory G:\test\Encrypted -outputDirectory G:\test\Clear -encrypt 0

Quick Links

Leave a Comment
  • Please add 2 and 6 and type the answer here:
  • Post
Wiki - Revision Comment List(Revision Comment)
Sort by: Published Date | Most Recent | Most Useful
  • Richard Mueller edited Revision 9. Comment: Removed (en-US) from title, added tag

Page 1 of 1 (1 items)
Wikis - Comment List
Sort by: Published Date | Most Recent | Most Useful
Posting comments is temporarily disabled until 10:00am PST on Saturday, December 14th. Thank you for your patience.
Page 1 of 1 (2 items)