Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

Expand Archive Wont Execute In ObjectEvent

$
0
0

Hello,

I am using a IO.FileSystemWatcher FileCreated object event to detect when a zip file is placed in a folder, once the zip is detected the script needs to extract the contents and save the files in another directory. If I simply callExpand-Archive C:\source.zip -DestinationPath C:\dest\ -Verbose -Force inside the IO.FileSystemWatcher FileCreated object event, the output window saysVERBOSE: Performing the operation "Expand-Archive" on target "C:\source.zip". and will hang here during execution forever.

If I place the cmdlet Expand-Archive outside of the object event, everything works, all contents in the zip file are extracted. This seems to me that there is a different thread the object event is located on. How would i getExpand-Archive cmdlet to work inside a object event? Below is the script that wont expand a zip file.


Register-ObjectEvent $fileWatcher Created -SourceIdentifier FileCreated -Action {
Expand-Archive C:\source.zip -DestinationPath C:\dest\ -Verbose -Force
}

Viewing all articles
Browse latest Browse all 15028

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>