Connecting mainframe application developers to discuss efficiently creating and maintaining z/OS applications
Installation Manager has a command line interface, so I would imagine that you could write a script to accomplish your goal
https://www.ibm.com/docs/en/installation-manager/1.8.5?topic=line-uninstalling-packages-by-using-imcl-commands