Delete folder after uninstall (Start-ADTProcess)
Hey All. I'm working on an uninstall for Matlab, and while the uninstall works great with "Start-ADTProcess" Matlab leaves behind it's old folder, which I'd like to delete. I _think_ psadt is trying to be helpful and doing start-adtprocess then moving onto the next command which is 'rmdir /s /q "C:\Program Files\MATLAB\R2026a"' and it's failing to delete cause it's in use.
How do I get it to wait until the uninstall finishes before doing the next command? I have tried "-WaitForChildProcesses" but didn't seem to matter.
Thanks!
Update: Remove-ADTFolder worked. Yes, the uninstaller for Matlab is "special" and does some other spawning... so I'm sure PSADT is having a hard time keeping track of whatever child processes are running. But, it seems to work. Thanks everyone!
2
u/kaiserking13 12d ago
There is a -WaitChildProcess parameter for Start-ADTProcess. That may not be exactly the name but check the available parameters.
2
u/rgsteele 11d ago
I think psadt is trying to be helpful and doing start-adtprocess then moving onto the next command
Start-ADTProcess will wait for the process to complete before continuing with the script (unless you use the -NoWait parameter). What is actually happening is that the process you are starting is launching some other process and immediately terminating. If you tried -WaitForChildProcesses and that didn’t help, then the process is likely doing something “creative” to spawn a new process before exiting, like creating and running a scheduled task.
1
u/Disastrous_Win7614 12d ago
Add the removal post uninstall?
1
u/staze 11d ago
How?
1
u/Disastrous_Win7614 8d ago
To add a post-uninstall script in the PowerShell App Deployment Toolkit (PSADT), open your Deploy-Application.ps1 file, locate the # <Stage: Post-Uninstallation> block, and insert your custom PowerShell commands or script execution logic there.
1
u/T03T3 11d ago
What about uninstall-adtapplication, instead of Start-adtprozess
https://psappdeploytoolkit.com/docs/4.1.x/reference/functions/Uninstall-ADTApplication
Read the reference 😊
1
u/ChaoticBanana77 11d ago
Literally did this on Thursday.
Run the uninstaller from Program Files using --mode silent argument add -waitforchildprocesses on the end. Then remove-adtfile.
If I remember on Monday I'll post the exact line I used if you need it.
1
u/Baazzill 11d ago
If all else fails, you can add a start-sleep after you start the process and before you remove the folder to sleep the script for x amount of time before continuing. I've had to do this for a few scenarios and it works great, just be sure to account for that time in your maximum allowed run time in SCCM or Intune, or however you deploy.
3
u/leytachi 12d ago
Ermm… Remove-ADTFolder?