It works just fine here.

Dot-source it instead of executing it, and look at $oncreated.Error.

Ensure that you are unregistering unused (that is OLD) events, so that you 
don't have multiple event firing on the same file.

Regards,

Michael B. Smith
Consultant and Exchange MVP
http://TheEssentialExchange.com

From: Joseph L. Casale [mailto:[email protected]]
Sent: Wednesday, January 26, 2011 5:53 PM
To: NT System Admin Issues
Subject: RE: PowerShell io notify sporadic behavior

I thought of that, and ran ps with an elevated shell, didn't help?
Odd!
jlc

From: Michael B. Smith [mailto:[email protected]]
Sent: Wednesday, January 26, 2011 3:47 PM
To: NT System Admin Issues
Subject: RE: PowerShell io notify sporadic behavior

Seems likely to be UAC or some other permissions related issue.

Regards,

Michael B. Smith
Consultant and Exchange MVP
http://TheEssentialExchange.com

From: Joseph L. Casale [mailto:[email protected]]
Sent: Wednesday, January 26, 2011 5:39 PM
To: NT System Admin Issues
Subject: PowerShell io notify sporadic behavior

On my Win7 x86 wkst's, this code works every time, perfectly.
On a vanilla 2008r2 server, it sometimes works, but mostly always fails to move 
the file?
Anyone have an idea why that might be?

$folder = 'D:\Test'
$filter = '*.*'
$destination = 'D:\Test2'
$fsw = New-Object IO.FileSystemWatcher $folder, $filter -Property @{
IncludeSubdirectories = $true
NotifyFilter = [IO.NotifyFilters]'FileName, LastWrite'
}
$onCreated = Register-ObjectEvent $fsw Created -SourceIdentifier FileCreated 
-Action {
$path = $Event.SourceEventArgs.FullPath
$name = $Event.SourceEventArgs.Name
$changeType = $Event.SourceEventArgs.ChangeType
$timeStamp = $Event.TimeGenerated
Write-Host "The file '$name' was $changeType at $timeStamp"
Move-Item $path -Destination $destination -Force -Verbose
}

Thanks!
jlc

~ Finally, powerful endpoint security that ISN'T a resource hog! ~
~ <http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/>  ~

---
To manage subscriptions click here: 
http://lyris.sunbelt-software.com/read/my_forums/
or send an email to 
[email protected]<mailto:[email protected]>
with the body: unsubscribe ntsysadmin

~ Finally, powerful endpoint security that ISN'T a resource hog! ~
~ <http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/>  ~

---
To manage subscriptions click here: 
http://lyris.sunbelt-software.com/read/my_forums/
or send an email to 
[email protected]<mailto:[email protected]>
with the body: unsubscribe ntsysadmin

~ Finally, powerful endpoint security that ISN'T a resource hog! ~
~ <http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/>  ~

---
To manage subscriptions click here: 
http://lyris.sunbelt-software.com/read/my_forums/
or send an email to 
[email protected]<mailto:[email protected]>
with the body: unsubscribe ntsysadmin

~ Finally, powerful endpoint security that ISN'T a resource hog! ~
~ <http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/>  ~

---
To manage subscriptions click here: 
http://lyris.sunbelt-software.com/read/my_forums/
or send an email to [email protected]
with the body: unsubscribe ntsysadmin

Reply via email to