I was trying to execute powershell in parallel mode. I was advised to create an event which will trigger whenever there is a change in folder.
For ex: If a folder name called "test1" is created in a particular folder then my powershell script test1.ps1 should be triggered.
I was trying to get example for this with Register-Objevent , but i am not getting any good clue.
If you have implemented some thing like this , can you please guide me?
Updated:
When i create a file named test1.ps1 in the "D:\ParallelEvent\temp" folder, it should execute test1.ps1 powershell file. Following is the code for that
$ScriptLoc="D:\My_Scripts"
$watcher = New-Object System.IO.FileSystemWatcher -Property @{Path = 'D:\ParallelEvent\temp';Filter = '*.txt';NotifyFilter = [System.IO.NotifyFilters]'FileName,LastWrite'}
$CreatedAction =
{
$FilenamewithoutExtn=$(($event.sourceEventArgs.Name).Split('.')[0])
Start-Job $ScriptLoc\$FilenamewithoutExtn.ps1
Get-Job -State Running | Wait-Job
}
Register-ObjectEvent -InputObject $watcher -EventName Created -SourceIdentifier FileCreated -Action $CreatedAction
My test1.ps1 has following line
[system.windows.forms.messagebox]::show("Hello, Test1!")
But still it doesn't execute the test1.ps1 it seems. I did not get any messagebox. Am i missing any thing?