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