When developing larger SharePoint solutions (with multiple developers and environments), we normally write a series of PowerShell scripts to ensure that all our custom functionality and structure can be repeatedly deployed. The problem that commonly arises with this is that SharePoint solution files (wsps) are deployed asynchronously, meaning that later operations in PowerShell scripts can fail. A while ago, i posted a rough article on execadmsvcjobs with SharePoint 2010 (click here to view the original article). I have experimented polling the “Deployed” property of a WSP in PowerShell, however I did not find this robust in some cases.
I have recently hardened my mechanism to ensure that my PowerShell scripts wait synchronously for solutions to deploy / retract as follows (based on a excellent post by Gary LaPointe (see here))
Note that this example assumes a solution to be activated globally (i.e. not at a specific webapp), and that also deploys to the GAC.