Powershell scripts allow you to take advantage of .NET libraries and write scripts which are almost as powerful as the .NET code itself. You can do many powerful operations like call external DLLs, use .NET namespaces like System.IO, System.Net, run processes and intercept output, call web services etc. The possibilities are endless. Here, I will show you a Powershell script which assists you in day to day deployment of websites. Everyday, we make changes to web projects, which need to be deployed to development servers, sometimes on beta servers, and finally on the production server. Using this script, you can automate all the manual work that you do again and again on your deployment package every time you upload your website to some server. We use this script in Pageflakes every single day during our local development server upload, beta release, and final production server release. All we do is run the script, go to the server, and extract a zip file on the web folder, and that's all. The new version gets deployed within two minutes without any manual work at all, and completely removes any possibility of human error during deployment.
Automating deployment
i have written a Powershell script does the following for you:
* Maintains different configuration information for different deployments. For example, different connection strings for development servers and production servers (one or more production servers).
* Creates a deployment folder using the deployment date, time, and version so that you have a separate folder for each deployment and can keep track of things deployed on a day, e.g., 20061214-1.
* Copies only the change files and some predefined files to the deployment folder. So, you don't deploy the whole website every day.
* Copies the web.config and customizes the <appSettings>, <connectionString>, <assemblies> etc., as per the deployment configuration. For example, you can have different connection strings for different servers.
* Updates all JavaScript files with a version number so that in every deployment, a new file gets downloaded by client browsers.
* Updates default.aspx automatically with the modified script file name.
* Compresses all JavaScript files that gets deployed.
* Compresses all static HTML files using an Absolute HTML Optimizer.
* Creates a zip file which contains the deployment package.
* FTP the zip file to a target server.
After the deployment script runs, all you need to do is extract the zip file on the server and that's all!
You can easily FTP the modified files instead of copying only the zip file, by changing the FTP part at the end of the script.