Saturday, July 4, 2009

IIS Workstation: Successful 1st Anniversary

Recently, I successfully completed 1 year of my blog IIS Workstation. It was the year of recession, year of financial crisis, year of elections, year of new relations, year of global disturbances; but for me it was the year of learning. I think I have learned more than ever by contributing to one and all through this blog. I also became an IIS MVP during this year so can't complain. :-)

I was just going through the site analytics to celebrate by contributions to the community and realized it would be even greater if I shared it with you. For, without my readers I would not have learned so much. Following is a snapshot of my blog details:

Analysis Period: 13 months
Total Page views: 37,646
% New visits: 90.06%

Traffic Sources:
Search Engines: 85.84%
Referring Sites: 7.33%

Geographies:
Site Viewed in: 163 countries
Top 3 Countries in order of views: United States of America, India, United Kingdom

Search:
Top Keywords on Google:
difference between iis 6 and 7 - Rank 1 (checked on July 4th 2009)
how to open iis admin - Rank 1 (checked on July 4th 2009)
difference between iis application and virtual directory - Rank 1 (checked on July 4th 2009)
substatus code - Rank 1 (checked on July 4th 2009)
iis admin could not start - Rank 1 (checked on July 4th 2009)

Top 5 Pages (Most viewed):
Difference between Virtual Directory and an Application in IIS
How To: Create a Website using IIS 6 - Level 100
Troubleshooting: Could not start the IIS Admin Service on Local Computer
Troubleshooting: IIS 6 Status and Substatus codes
IIS Workstation

Hope this year turns out to be good news as well for me. Have fun and keep watching this place for more info!

Oh and Thanks! :)

Sessions: Tech Ed on the Road, HydTechies

I recently took a couple of sessions on IIS 7 & 7.5 as part of Hyderabad Techies and "Tech-Ed on the Road" revival campaign here in Hyderabad, India. It was great to see the enthusiasm people had for different Microsoft technologies. We had sessions ranging from ASP.NET - Windows Azure and IIS - to SQL Server 2008.

I was responsible for delivering sessions on IIS 7.5 which is going to ship along with Windows Server 2008 R2 and Windows 7. I think I was kind of lucky in that sense, because there is always so much to speak on IIS. There is so much that is running on the web these days and you love it when lots of it is running on IIS.

I knew the best way to spread the word on IIS, is to show what makes IIS the way it is. Then lets leave it to the people to decide what they want... shouldn't we? Anyways, I started from level 100, so that I could show the basic architectural changes in IIS 6 and IIS 7. Detailed explanation can be found in my previous post on differences between IIS 6 and IIS 7 and IIS: changes from 6 to 7.

Moving on I showed the advancements in IIS UI, IIS security and IIS extensions and how they help both the Admins and the developers. IIS extension are these out of band modules which are released by the IIS PG and the community making use of the great extensibility modules available.

It was great to see how much people loved the idea of including a module and the ease of it's installation which originally dint come with the product.

As promised, details on the IIS extensions and download location can be found at http://www.iis.net/extensions. All the information on the Microsoft web application gallery and platform can be found here.

Check out this cool blog on IIS history to see and learn how IIS has evolved. It also answers the 1st question I always face when speaking on IIS... "How to download IIS" ... :)

Have fun... !!!

Sunday, June 14, 2009

Troubleshooting: IIS Powershell Module on Windows 7 RC

First thing that you need to know in regard to the IIS PowerShell Snap-in or the module when using it with Windows 7 is that you do not need to download & install the snap-in. In Windows 7 the snap-in is part of the default install of IIS. Moving on, if you want to use the snap-in with PowerShell in Windows 7 RC then you would need to import the module. Now that sounds simple. However, there is a problem. When you try to import the IIS module which is named WebAdministration you are most likely to view the error below.

PS C:\Users\admin> Import-Module WebAdministration
Process should have elevated status to access IIS configuration data.

Fair enough. We are going to access the configuration data from IIS, we would need to be on elevated privileges. Let's try with elevated privileges.

PS C:\Windows\system32> Import-Module WebAdministration
Import-Module : File C:\Windows\system32\WindowsPowerShell\v1.0\Modules\WebAdministration\WebAdministrationAliases.ps1 cannot be loaded because the execution of scripts is disabled on this system. Please see "get-help about_signing" for more details.


Huh! Now, why did this happen? Lets try and troubleshoot. Windows PowerShell has a concept called "Execution Policy". It is the execution policy that determines as to how a script runs on PowerShell. By default, the execution policy in Windows 7 RC is set at "Restricted" ... Oouch. Restricted here means you will not be able to run any script (even the ones you write yourself). Why so severe? Don't know so can't answer. But for sure we wouldn't be working with that execution policy and would have to change that.

There are several levels of Execution Policy that you can set like Restricted, All Signed, RemoteSigned and Unrestricted. But the one we are going to work with is RemoteSigned. So, what is RemoteSigned execution policy anyways? It means, if you want to configure PowerShell to run any scripts that you write yourself, but to run scripts downloaded from the Internet only if those scripts have been signed by a trusted publisher. Sounds fair enough now doesn't it.

To set RemoteSigned as the execution policy, run the following command.
> Set-ExecutionPolicy RemoteSigned

Lets try importing now.
PS C:\Windows\system32> Import-Module WebAdministration
Import-Module : The following error occurred while loading the extended type data file:
Microsoft.PowerShell, C:\Windows\system32\WindowsPowerShell\v1.0\Modules\WebAdministration\iisprovider.types.ps1xml : File skipped because it was already present from "Microsoft.PowerShell".

No go even now :) . When we try to execute any IIS cmd-let like get-website we will get an not recognised cmd-let error. Here's how to solve the entire situation. Close the PowerShell window and re-open it with elevated privileges and enter Get-ExecutionPolicy:

> Get-ExecutionPolicy
RemoteSigned

That's good news ... no more Restricted. Lets try importing the IIS module yet again.

>Import-Module WebAdministration

No error. Success! Now lets try running some simple IIS cmd-let.

> Get-Website

Name ID State Physical Path bindings
---- -- ----- ------------- ---------
Default Web Site 1 Started %SystemDrive%\inetpub\wwwroot http *:80:

Problem Solved! However, to me this still looks like a workaround. Will let you know if and when I come across a solution to this. Till then, have fun!

Update:

Check out this blog from sergeia on how to automate PowerShell snap-in. Will save you time from re-work.

Update2: I am having some problem publishing comments on my site. But here's another update from JeongHwan of the IIS team.

--------------------------------------------------------------------------------------------

Here is the blog how to start IIS module.

blogs.iis.net/.../how-to-automate-windows-7-powershell-start-up-with-iis-module.aspx

FYI, if you want to use AllSigned execution-policy instead of RemoteSigned and avoid the error message, another work-around is to sign the C:\Windows\system32\WindowsPowerShell\v1.0\Modules\WebAdministration\WebAdministrationAliases.ps1 file as the following:

1. Create a certificate using makecert.exe tool, which can be downloaded from Microsoft web site (www.microsoft.com/.../details.aspx) if you don’t have any certificate for signing powershell script files

md %systemdrive%\PowershellCertificate

makecert -n "CN=PowerShell Local Certificate Root" -a sha1 -eku 1.3.6.1.5.5.7.3.3 -r -sv root.pvk root.cer -ss Root -sr localMachine

makecert -pe -n "CN=PowerShell User" -ss MY -a sha1 -eku 1.3.6.1.5.5.7.3.3 -iv root.pvk -ic root.cer

2. Change the file owner for the WebAdministrationAliases.ps1 file from TrustedInstaller to local administrator and then give full permission to local administrator for the file using Explorer.exe

3. Sign the WebAdministrationAliases.ps1 file with the newly created certificate or other existing certificate for powershell script files

$targetfile = "$env:windir\system32\WindowsPowerShell\v1.0\Modules\WebAdministration\webadministrationaliases.ps1"

Set-AuthenticodeSignature $targetfile @(Get-ChildItem cert:\CurrentUser\My -codesigning)[0] ## suposing the first certificate is the newly created one

4. Change execution policy to “AllSigned” if the current policy is “Restricted”

Set-ExecutionPolicy AllSigned

5. Import IIS module and there will be no error

Import-module webadministration

-----------------------------------------------------------------------------------

Hope it helps!