# DLP Existing Files Scan Tool

Data Loss Prevention (DLP) features in ShareFile let you restrict access and sharing based on the content found within a file.

This tool allows you to:

* Scan files stored on your StorageZone prior to [enabling the DLP integration](https://docs.sharefile.com/en-us/sharefile/storage-zones-controller/6-0/data-loss-prevention)
* Re-scan uploaded files

## Tool Requirements

* The DLP Integration must be enabled at the StorageZones Controller console. See [Enable DLP](https://docs.sharefile.com/en-us/sharefile/storage-zones-controller/6-0/data-loss-prevention) for more information.
* PsExec.exe must be used in order to run the tool with Network Service Rights.

## Obtain Network Service Rights

Use PSExec to launch PowerShell (x86) under the same user context as the StorageZone Controller and obtain Network Service Rights using the following command:

* `PsExec.exe -i -u "NT AUTHORITY\NetworkService" C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell`

## Initiate a Scan

First, in the PowerShell window created in the previous step, navigate to the DLPExistingFiles.ps1 tool’s install location.

* `Example: PS C:\> cd ‘C:\inetpub\wwwroot\ShareFile\StorageCenter\Tools\DLPExistingFiles’`

To initiate a scan, run the following command:

`.\DLPExistingFiles.ps1 –runscan <scanType> -date <date> -queueLimit <queueLimit>`

> **Note:**
>
> `<scanType>` is required. `<date>` and `<queueLimit>` are optional.\`

\--

> **Important:**
>
> If you have run the scan tool previously, please ensure that the `Enddate.temp file` located at `C:\inetpub\wwwroot\ShareFile\StorageCenter\SC\Enddate.temp` has been deleted before running a scan or scheduling a scan via Task Scheduler.

## Custom Scan Options

You can customize your DLP scan with the following options:

**scanType** – This is a required variable. You may set scanType to the following:

* Unscanned
* Scanned (this type will scan all files that have been scanned previously, both OK and Rejected)
* ScannedOK
* ScannedRejected

**Date** – This is an optional variable. If the date is not set, the tool will scan all pre-existing files uploaded prior to the current date and time. To provide date and time, use the following format:

* Mm/dd/yyyy/ hh:mm:ss AM/PM
* Example: 09/21/2015/ 10:11:12 AM

**queueLimit** – This is an optional variable. The queueLimit is the max number of files that may be fetched for scanning at a time. By default, the value will be taken from app.config. The default is 512. When a queueLimit is reached, a temp file is created at the following location:

* `PS C:\> cd ‘C:\inetpub\wwwroot\ShareFile\StorageCenter\SC\Enddate.temp`

> **Note regarding the Enddate.temp file:**
>
> The Enddate.temp file must be deleted before running the tool manually or scheduling a scan via Task Scheduler.

## Schedule Recurring Scans via Task Scheduler

You may configure a recurring scan to run via Windows Task Scheduler. To do so:

1. Open Windows Task Scheduler.

2. Navigate to the **Access Pane** and select **Create Task**.

3. Under **General**, provide a **Name** for your task.

4. Under **Security Options**, click **Change User or Group**.

5. Enter the **Object Name** as **Network Service** or as a named user with write permissions to the storage location.

6. Under **Configure For**, select the correct operating system for your setup.

7. Under **Trigger**, configure the frequency for running the recovery task as needed.

8. Under **Actions**, create a **New Action** with the following parameters:

   * **Action:** **Start a Program**
   * **Program/script:** `C:\Windows\System32\cmd.exe`
   * **Argument:** `/C "c:\Windows\syswow64\WindowsPowerShell\v1.0\PowerShell.exe -File .\DLPExistingFiles.ps1 -runscan <scantype> -queueLimit <queueLimit>"`
   * **Start In:** `c:\inetpub\wwwroot\ShareFile\StorageCenter\Tools\DLPExistingFiles`

9. Conditions and Settings are optional.

10. Click **OK**.

Once all files have been scanned, you may stop the scheduled task.

## Troubleshooting

### Logs

Logs for the DLPExistingFiles.ps1 tool may be found at:

* `C:\inetpub\wwwroot\ShareFile\StorageCenter\SC\logs\DLPExistingFiles-<date>.txt`

### Error: “Cannot run PsExec.exe –i –u “NT AUTHORITY\NetworkService”

Verify your permissions and ensure you have appropriate access to the network service.

### Error: “DLP Integration Needs to be Configured”

Ensure that the DLP Integration is enabled on the StorageZones Controller console.
