How to automate Windows 7 PowerShell start-up with IIS Module

Some of our customers don't like to make multiple steps that required to bring IIS module into PowerShell in WIndows 7 RC. Fortunately, there is a way to automate this routine, like we did for Out-Of-Band release.

1. If you are getting errors like "File <your profile>\profile.ps1" cannot be loaded. Cannot sign file ...", you will need to relax execution policy or sign the file. It is pretty safe to limit requirement to have signed scripts to remote scripts only. To do this, execute command

set-executionpolicy remotesigned

Then close and reopen PowerShell. This is one time operation, PowerShell will save your setting.

2. Now let's create shortcut that will start PowerShell in elevated mode and immediately import IIS module. In Windows 7 you could also place this shortcut to menu or task bar to have it handy.

Copy shortcut to WIndows PowerShell from Start Menu/Accessories/Windows PowerShell to the desktop. Now right click this shortcut and click on properties. In the box Target add parameter to the PowerShell.exe, you will need complete command line like this:

%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe -noexit -command "import-module webadministration | out-null"

This will load IIS module on PowerShell start-up. The last step is to make this shortcut elevated. Click on Advanced button and check box "Run as administrator". Click OK, click OK. Try this shortcut, your could edit it's name to reflect your changes, like "IIS Console".

3. Last step is to 'pin' this shortcut. Press Shift and do right click on the shortcut icon. You will see two new menu "Pin to Task Bar" and "Pin to Start Menu". Select what you need, and shortcut will be placed either into Task bar or into Setup menu. If you do right click on it in the Task bar, you will see number of other 'pinned' shortcuts, that PowerShell team added, they could also be useful.

Enjoy,

Sergei

3 Comments

  • Question about how to import modules on a remote server. I'm trying to remotely stop an IIS website with the following command but it doesnt seem to work (although it doesnt report an error either).

    powershell -command "icm hydrogen {import-module webadministration | stop-webitem iis:\sites\mysite}"

    Any thought on why this doesnt work?

    CT

  • What is "icm hydrogen"?
    Are you sure your remote server has webadministration module installed?

  • Here is how I solved this issue...

    http://www.tadlockenterprises.com/2009/12/remote-admin-iis-for-tfs-2010-builds/

    I gave up on using the IIS Powershell cmdlets; it's far easier and more flexible to use appcmd.exe.

Comments have been disabled for this content.