PowerShell is a command-line tool which allows you to run commands and scripts, to change system settings and automate tasks.
It can, for example, be used in the Process Triggers tab of the Events panel of the CompleteFTP Manager, to check that the information of the events is saved in the created file in the script.
CompleteFTP makes the details of the event (the file name, the user, the time, and so on) available to your PowerShell script as environment variables. Reference them as ${env:FileName}, ${env:LoginUserName}, and so on. The variable name is the macro name without the % signs; the date/time values are prefixed with Event (${env:EventDate}, ${env:EventTime}, ${env:EventDateAndTime}). The full list is on the Macros page, and the Manager's macro menu inserts the correct form for you.
This script checks that the Upload file event works properly, with the PowerShell script type.
# Create a PowerShell_Result.txt file in C:\Temp contains the information of the newly uploaded file
$path = 'C:\Temp\PowerShell_Result.txt'
$value = "${env:FileName} has been uploaded by ${env:LoginUserName} at ${env:EventTime}"
Add-Content -path $path -Value $value
Note: the older %FileName% / %Time% form is still supported for backward compatibility, but is not recommended for new scripts: values substituted that way have characters that are special to PowerShell replaced with underscores. Prefer the ${env:FileName} form above, which delivers the value unchanged. See Using macro values safely.
1. Go to the "Process Triggers" tab, add a new process trigger for an Upload file event.
2. Configure the process trigger as follows:
3. Input the above script with PowerShell Script, then 'Apply changes'.
4. From your FTP client, connect to the CompleteFTP server with the user user1 and upload a file to the server -> Verify that the user is logged in and that the upload is successful.
5. Navigate to C:\Temp and verify that there is a PowerShell_Result.txt file, which contains the information of the newly uploaded file.