# Expand Archive Wont Complete Execution In Object Event

**URL:** <https://forums.powershell.org/t/expand-archive-wont-complete-execution-in-object-event/15100>\
**Category:** PowerShell Help\
**Created:** [October 16, 2020, 8:03am UTC](https://forums.powershell.org/t/expand-archive-wont-complete-execution-in-object-event/15100 "2020-10-16T08:03:21Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ghzn88](https://avatars.discourse-cdn.com/v4/letter/g/85f322/32.png) [@ghzn88](https://forums.powershell.org/u/ghzn88)\
**Post date:** [October 16, 2020, 8:03am UTC](https://forums.powershell.org/t/expand-archive-wont-complete-execution-in-object-event/15100/1 "2020-10-16T08:03:21Z")

</div>

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 call `Expand-Archive C:\source.zip -DestinationPath C:\dest\ -Verbose -Force` inside the IO.FileSystemWatcher FileCreated object event, the output window says VERBOSE: 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 get `Expand-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
}
```

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:28pm UTC](https://forums.powershell.org/t/expand-archive-wont-complete-execution-in-object-event/15100/2 "2024-05-16T20:28:43Z")

</div>

Closed on May 16, 2024, 8:28pm UTC


