Recently I was tasked with the task of creating an automatic extraction and importing solution using PowerShell Scripts. To do this I created two files one for export and extracting with the other in charge of pack and importing the solution. I was using the Visual Studio template of CRM Package that comes with the sdk.
Export and Extracting The Solution
First thing I did was implement the export and extraction of the CRM solution. The PowerShell script first exports the solution from the web using a module called Microsoft.Xrm.Data.PowerShell. Then it extracts the downloaded zip into a folder for the correct file structure. A nice thing about using the Microsoft.Xrm.Data.PowerShell dll is the fact it gives you additional CRM commands you can do. For example before downloading the solution it allows you to change the version number of the solution before downloading.