Share this Post

JC Blogs

Recent Posts

Hello, my names is James and for my first blog I would like to answer some of the common questions I have seen when using MSDeploy in Powershell for the first time. Also, I will try to introduce some tricks to help gather information about your server using the MSDeploy Powershell environment.

Q. What is the name of the Powershell snap-in, how do I see if it installed ?

A. The name of the snap-in is "MSDeploysnapin". At the PS command prompt you can use the Get-pssnapin -registered cmdlet to verify the snap-in is installed. You can use add-pssnapin MSDeploysnapin at the PS command prompt to include the snap-in.

Q. MSDeploy installed on the machine and then I installed Powershell, but I don't see the snap-in as being installed?

A. You have to install MS Deploy after you have installed Powershell on your server, the snap-in cannot be installed into the registry properly until Powershell is installed so it has to be done in this order.

Q. What cmdlets are available in the MSDeploysnapin?

A. The cmdlets have been finalized to Get-deploymentObject and Update-deploymentObject.

Q. Are there any shortcuts I can use when typing cmdlets?

A. If you use Get-help Get-deploymentObject-full or Get-help Update-deploymentObject -full you can see that the certain parameters have assigned default positions. This allows shortcuts for the following two scenarios.

Another technique to troubleshoot these situations is to check your $source data first for validity and then perform the update again ( this can be done just by removing the $source = and verifying an object is returned first ) . In some scenarios checking the $dest object will only show an invalid object since it is null initially but MSDeploy allows this since it is necessary for updates.

Q. Do I need to use the -migrate switch when migrating my server from IIS6 to IIS7?

A. Short answer is no, you do not. The migrate switch adds some additional rules that may be useful in a migration but it is not required. Unlike the command line tool, you do not need to distinguish between migrations and sync when using Update-deploymentObject.

Q. Do I need to install Powershell on every web server to use cmdlets on multiple servers remotely ?

A. You only need to have the MS Deploy agent service called "msdepsvc" started on all other web servers. Powershell and the MSDeploysnapin need only be installed on the operator machine.

Q. How can I get dependencies of my web server in a Powershell session ?

A. Credentials in Powershell use the -credential switch ( the direct input for this switch can be a credentials object or just the username ) and there is a way to pass both the username and password remotely by creating a credential object first and passing it as a parameter. If your credential object only contains a username you will be prompted for a password. The following example creates a deployment object from an IIS7 web-server remotely and stores it in the $server variable. In this example, you would be prompted for a password directly after executing this cmdlet.

You will then be prompted with a "password:" prompt that you can enter your password. This creates the file c:\encryptedpassword.txt. Whenever you want to script your password and avoid prompts just have this file handy on the server submitting the credentials. The next step is to create a secure string object with your password using the newly created file.

Now use this credential object in your Get-deploymentObject and voila, you no longer have to type out your password to do remote operations. Simply use the $credentials object as the parameter for credential switch.

Q. The command line tool for MSDeploy has a configuration file which I can add and configure rules I use for my web server, how can I do this in Powershell?

A. While it is possible to create rules on the PS command prompt, there is currently no configuration file used in Powershell sessions. This can be worked around by scripting common operations to script files and placing the rules there.

Q. I stored my web server to a deployment object ($server = Get-deploymentObject apphostconfig ) and then made changes to my web server. Why are my changes not showing up in deployment object?

(** The following has been updated as of 3/4/09)

A. This has changed slightly from previous versions. Your $server object will be more of a placeholder until it is used. That is to say until an operation is performed such as an Update, GetDependencies or GetSystemInfo it is a hollow object. Upon making the previously mentioned calls the object will then be created and validated at that time. To force this validation simply do something like $server.Invoke("GetSystemInfo").OuterXml, if you get system information back then the object is valid in this case.

Q. Is there a way I don't have to add the MSDeploysnapin manually to every Powershell session?

A. You can do this by starting a Powershell session and adding the MSDeploysnapin. Then, export your console with the following cmdlet ( this works for Vista Powershell version 1.0 ).

Export-Console -path <directory\filename>

This will create a file with a psc1 extension ( might be different for other Powershell versions ). Whatever shortcut you use to start Powershell, now add the following switch and argument.

Powershell.exe -PSConsoleFile c:\<filename>.psc1

This will load the MSDeploysnapin automatically and start your Powershell session. You can also create the psc1 file manually if you only want the MSDeploysnapin by saving the below xml to a psc1 file.

That's it for my first Powershell FAQ of MSDeploy. If there is anything else you would like to see in this blog, feel free to respond below and let me know. In the future, I hope to provide a deeper look into deployment objects and the MSDeploysnapin cmdlets.

Comments

Great post! How do I use Powershell to synchronize all websites from a host machine to mulitple destination machines at the same time, similiar to what the following cmd lines in MSDeploy will do:

Unfortunately there isn't any extra functionality here compared to command line, it would be almost the same with maybe one exception being you can create the source object ahead of time and reuse it, so something like:

Hey Anonymous, yes the cmdlets got yanked from RTW, this blog is pretty much obsolete if you are using RTW. I started some blogs about making functions in powershell to make use of MSDeploy through APIs, but I hope to see MSDeploy snapin make a come back for future releases of MSDeploy.