I have similar scripts and I encountered a similar behavior recently. In my case, it turned out that I was executing the powershell script with the "Run PowerShell script" task, as I saw you are doing. The solution is to run this as a "Run Command Line" task. The explanation could be this: When you run the PowerShell native task, the script is executed in the same process as the Task Sequence, and when it closes the Task Sequence GUI, it closes also it's own GUI, hanging itself... When you run this with the Command Line task, it opens a new powershell process, that closes and resumes the Task Sequence GUI.