That's probably a simple question for someone who knows Powershell. I have already tried to implement the suggestions of several answers to similar questions, such as these and these. I have a filewatcher that monitors a folder and writes a log file in case of changes. This works well.
What I didn't manage to do is to execute an additional Python script. I am grateful for any advice.
$folder = 'F:\myPath\myFolder' # Enter the root path you want to monitor.
$filter = '*.*' # You can enter a wildcard filter here.
# In the following line, you can change 'IncludeSubdirectories to $true if required.
$fsw = New-Object IO.FileSystemWatcher $folder, $filter -Property @{IncludeSubdirectories = $false;NotifyFilter = [IO.NotifyFilters]'FileName, LastWrite'}
# Registered events:
Register-ObjectEvent $fsw Renamed -SourceIdentifier FileRenamed -Action {
$OldName = $Event.SourceEventArgs.OldName
$name = $Event.SourceEventArgs.Name
$changeType = $Event.SourceEventArgs.ChangeType
$timeStamp = $Event.TimeGenerated
Write-Host "The file '$name' was $changeType at $timeStamp" -fore white
Out-File -FilePath F:\myPath\myLogFile.txt -Append -InputObject "The file $name was $changeType at $timeStamp"
python F:\myPath\myPythonScript.py}
How can I achieve this with Powershell ISE?