Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # this function should be called when a new file is created
- function foobar(){
- $form.BackColor = "black"
- }
- # set up runspace for async FileSystemWatcher
- $Runspace = [runspacefactory]::CreateRunspace()
- $PowerShell = [System.Management.Automation.PowerShell]::Create()
- $PowerShell.runspace = $Runspace
- $Runspace.Open()
- [void]$PowerShell.AddScript({
- $logFile = 'C:powershelltest.log'
- $dirName = 'C:powershell'
- $hotFolder = New-Object IO.FileSystemWatcher $dirName -Property @{IncludeSubdirectories = $false;NotifyFilter = [IO.NotifyFilters]'FileName, LastWrite'}
- Register-ObjectEvent $hotFolder Created -SourceIdentifier FileCreated -Action {
- $name = $Event.SourceEventArgs.Name
- $path = $Event.SourceEventArgs.FullPath
- $changeType = $Event.SourceEventArgs.ChangeType
- $timeStamp = $Event.TimeGenerated
- Out-File -FilePath $logFile -Append -InputObject "The file '$name' was $changeType at $timeStamp"
- # this call does not work
- foobar
- }
- })
- $AsyncObject = $PowerShell.BeginInvoke()
- # set up form
- $form = New-Object System.Windows.Forms.Form
- $form.ShowDisplay()
Add Comment
Please, Sign In to add comment