Depends on how you execute the script. :) But yes, the Action is an independent scope.
Payette covers that in detail in his second edition. Regards, Michael B. Smith Consultant and Exchange MVP http://TheEssentialExchange.com From: Joseph L. Casale [mailto:[email protected]] Sent: Wednesday, January 26, 2011 6:06 PM To: NT System Admin Issues Subject: RE: PowerShell io notify sporadic behavior FFS, Scoping issue. $destination isn't available in the Move-Item part of the code? So this var gets instantiated with local, so its outside the function, right? I re-scoped this to "script" and that worked, is that correct? Thanks guys! jlc Ps. The sometimes working was obviously the myriad of cmd's left in the shell by trying everything until it dawned on me. 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
