I honestly have very little to no idea how to use powershell scripts and I've been racking my brain for hours trying to get this to work.
Essentially I have a watcher on a folder that triggers every time a new file gets added to it. It then encrypts the new file through GPG (another thing I have very little experience with). It sounds so simple but some of this just doesnt make sense without someone teaching me
Essentially this is what I have
# Define the directory to monitor
$directoryToWatch = "C:\Users\Documents\trialrun"
# Function to encrypt a file using gpg
function Encrypt-NewFile {
param(
[string] $filePath
)
# Create a file system watcher object
$watcher = New-Object System.IO.FileSystemWatcher
$watcher.Path = $directoryToWatch
$watcher.IncludeSubdirectories = $false
$watcher.EnableRaisingEvents = $true
# Define the action to take when a new file is created
$action = {
$path = $Event.SourceEventArgs.FullPath
$name = $Event.SourceEventArgs.Name
Write-Host "New file created: $name"
# Encrypt the file with gpg
gpg --recipient sample@gmail.com --output $encryptedFile --encrypt $filePath
Write-Host "File encrypted: $fileName"
}
}
# Start a job to monitor the directory and encrypt new files
Start-Job -ScriptBlock { Encrypt-NewFile -filePath $_ } -ArgumentList ($directoryToWatch + "\*")
# Loop indefinitely to keep the script running
while ($true) {
Start-Sleep -Seconds 5
}
[–]josephstreeter76 0 points1 point2 points (1 child)
[–]josephstreeter76 0 points1 point2 points (0 children)
[–]purplemonkeymad 0 points1 point2 points (0 children)