Guest User

Untitled

a guest
Feb 19th, 2018
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. # this function should be called when a new file is created
  2. function foobar(){
  3. $form.BackColor = "black"
  4. }
  5.  
  6. # set up runspace for async FileSystemWatcher
  7. $Runspace = [runspacefactory]::CreateRunspace()
  8. $PowerShell = [System.Management.Automation.PowerShell]::Create()
  9. $PowerShell.runspace = $Runspace
  10. $Runspace.Open()
  11.  
  12. [void]$PowerShell.AddScript({
  13. $logFile = 'C:powershelltest.log'
  14. $dirName = 'C:powershell'
  15.  
  16. $hotFolder = New-Object IO.FileSystemWatcher $dirName -Property @{IncludeSubdirectories = $false;NotifyFilter = [IO.NotifyFilters]'FileName, LastWrite'}
  17. Register-ObjectEvent $hotFolder Created -SourceIdentifier FileCreated -Action {
  18. $name = $Event.SourceEventArgs.Name
  19. $path = $Event.SourceEventArgs.FullPath
  20. $changeType = $Event.SourceEventArgs.ChangeType
  21. $timeStamp = $Event.TimeGenerated
  22.  
  23. Out-File -FilePath $logFile -Append -InputObject "The file '$name' was $changeType at $timeStamp"
  24.  
  25. # this call does not work
  26. foobar
  27. }
  28. })
  29.  
  30. $AsyncObject = $PowerShell.BeginInvoke()
  31.  
  32. # set up form
  33. $form = New-Object System.Windows.Forms.Form
  34. $form.ShowDisplay()
Add Comment
Please, Sign In to add comment