Muqeet's blog

  • Status Codes UI: Know the meaning of your Status Codes

    A lot of times I come across people who can read the IIS logs but cannot understand the meaning of the status codes mentioned. As always, they resort to a search engine to find out the meaning. Had some free time so I cooked up this little IIS 7 UI module that tells you the status code and its corresponding meaning. The setup for now is manual but I will work on a setup utility in a future release.

    Hope you find it useful. Please do leave your feedback, suggestions and comments as always.

    Installation Procedure:

    1. Grab a copy of the required files. Download it from here

    2. Copy sccheck_schema.xml into C:\Windows\System32\inetsrv\config\schema folder.

    3. Open ApplicationHost.config (C:\Windows\System32\inetsrv\config) and add

    <section name="sccheck" />
    under <sectionGroup name="system.webServer">

    4. Run the program addcodes.exe. You should be seeing an output as below:






    5. Now add sccheck.dll in the GAC.

    6. Open Administration.config (C:\Windows\System32\inetsrv\config) and place
    <add name="sccheck" type="sccheck.sccheckModuleProvider, sccheck, Version=1.0.0.0, Culture=neutral, PublicKeyToken=124c916c4cac2452"> in the module providers section.

    7. Again in the modules section of Administration.config add <add name="sccheck" />

    That's it. Now open up IIS Manager and in the Management category you should be seeing Status Codes. Open that up and you should be seeing the following:


    Status Codes in also integrated with the IIS configuration so you can also access the status codes explanation from appcmd.exe

    >appcmd.exe list config -section:sccheck








    It seems like an odd things when you see it individually. But, mix it up with your other modules and applications and you will get yourself a pretty good solution.

    Have Fun!

  • IIS 8 on Windows 8 Technical Preview

    Today Microsoft released the technical preview bits of its latest operating system "Windows 8" ... Though windows 8 is being show cased as the next generation tablet OS ... I had to install IIS as the 1st thing I did after "windows 8" install.

    Short Story: There is no real difference in the install experience from that of IIS 7...

    Long Story: You will still need to install IIS 8 from "Turn Windows Features on\off", however the way you reach there is slightly different now...

    • Once you are on the Home Screen (The new Metro UI coolness that you see everywhere) click on Control Panel
    • This will take you to a new control panel page (which looks simple and cool by the way) ... Once at this page go to the last option that says "More Settings"
    • This will get you to the familiar Windows 7 control panel settings page from wherein you will go to Programs --> Turn windows features on\off --> Internet Information Services --> Select --> leave Default and say ok
    • That's it... once the result displayed is success ... go to IE and browse localhost ... 

    The first noticeable difference you will find after you install IIS on Windows 8 TP is the localhost start page ... For all of you who haven't check it out yet ... here it is ...


    Will be posting a lot more once I am through configuring "IIS 8" ...

    Note: Check out how HTML 5, PHP and ASP.Net are included in number "8" ... Need I say more about Microsoft's commitment towards PHP and HTML 5 ?? 

    Next Steps ... Going to Run PHP :-) 

  • How do I listen to songs from my laptop on my Windows Phone 7?

    I have about 6 GB of audio collection saved under folder ("Songs") on my machine. I never felt it practical to sync my entire collection, however, every now and then I would miss listening to a song I hadn't synced yet ... so I had to find a solution to this problem... The answer to the above question is fairly simple - I 
    used IIS

    3 things I am using for this setup to work are: My laptop, Windows Phone 7 Device and a wireless router. 

    The laptop and HTC HD 7 are using the linksys router for obtaining an IP. Therefore they are pingable to each other. Once you confirm the ping, install IIS on your laptop or desktop machine in case you dont have it installed already. once IIS is installed, do the following:

    1. Copy all the songs you want to listen to a folder named "Songs" (For me it is C:\Songs)
    2. Open IIS Manager (Start->Run->inetmgr)
    3. Right-Click on Sites -> Add Web Site ... You will see the following image... Fill it up with the information as in the image.

    Note: Replace the IP address with the IP address of your machine

    4. You would also need to enable the directory listing module to see the list of songs that you would be playing. (I wanted to keep this as simple as possible hence DirList module)
     4.1 Select the website in IIS Manager and double click on the Directory Listing Module as shown below in Figure 1:





    Figure 1.

    Once you get into Directory browsing module on the right you will find the Alerts (Action Pane) as in Figure 2. 
                                                                              Figure 2.
    4.2. Click on the enable link. FYI, once you click it changes into disable.

    Well, that's about it. You can now browse your website by opening up IE on WP 7 and accessing your machine IP address. Following are a few things you should know about what kind of files you can place in this folder as not all files that play on your machine will play on your windows phone 7. 

    a. MP3 will be streamed automatically from your machine to your windows phone 7 device. There is nothing you have to do to make this work. 

    b. WMV will be streamed by default as well. For details, check: http://msdn.microsoft.com/en-us/library/ff462087(v=VS.92).aspx 

    c. You are not using any dynamic technology here. You are *NOT* using silverlight or Flash. Therefore, your MP3 files will work perfectly on an iPhone or an Android device as well. 

    d. If you want to make the page look good, you can download various custom directory browsing modules available on the internet. 

    e. This setup will of course work only in your home network. 

    Do let me know what you think about it. 

  • Google Adsense Domain Ownership Verification

    Hey All... I had applied for Google Adsense program and they couldn't admit me into their program as they were not sure about the Domain Ownership ... :-) They have asked me to create this page... so here it goes ...

    "This post confirms my ownership of the site and that this site adheres to Google AdSense
    program policies and Terms and Conditions: ca-pub-8263985038259751"

    No IIS stuff in this one ... :D

  • Presenting at Microsoft Tech-ED India

    Pretty heavy load of presentaions on my way for the next 3 weeks and yet I feel so excited.

    I will be speaking on IIS and the Widows Web Platform in general for engineering students here in Hyderabad on the 16th. I am so looking forward to this. My previous expiriences with students were real engaging; their enthusiasm, the eagerness to learn and adopt the technology is ashtonishing.

    Next, I will be kicking off my workshops on IIS 7 for freshers at Bangalore, Hyderabad and Pune in India. You can get more information on the training from here.

    From there I will shift to  LaLiT Ashok in Bangalore for the big show - Tech-Ed India. For those who are not aware, Tech-Ed India is the largest technical event in India by Microsoft. This time around Microsoft has arranged for Keynotes by Senior Microsoft Executives , Breakout Sessions, Hands-on-Labs, Instructor-led Labs, Product Team Tents, Free Microsoft Certification, Community Programs, Solution Expo, and many more. Apart from that I will also be speaking on "IIS - Deploy and manage Web applications, built using your choice of runtimes" from 4:15pm-5:15pm on the 25th this month. :-)

    You can register for the sessions and the event at the Tech-Ed India Website.

    Last 3 days of the month and I am conducting a real cool training on IIS 7 for a firm in Hyderabad. Love the travel, Love the technology ... Stayed tuned... Lots to update soon...

    Do check out the Tech-Ed India agenda ... Lots of sessions on IIS and surrounding technologies. See you there!

  • IIS Workstation now on Facebook

    Hey Everyone,
      Wanted to take this opportunity to let you all know that I have started a page for IIS Workstation on Facebook. You can check it out at http://www.facebook.com/iisworkstation. The idea behind this is to give short tips, tricks and solutions that really dont fit in a category for a blog. When it comes to IIS there are many such things which I plan to use this Facebook page for.

    See you on Facebook! Happy Posting!
    Regards,
    Muqeet Khan
    (ma_khan)

  • IIS Appcmd - All things CLI

    Past couple of days I was digging into Appcmd.exe - the command line tool for managing IIS 7 and 7.5 for an on-going project. If you are not yet aware of this tool yet, surprisingly you will not be the only one as somehow appcmd.exe hasn't been put to limits by a lot of IIS admins yet ...
    Appcmd is not only a useful tool for odd daily IIS tasks but its an excellent tool for automation. Commands in appcmd are pretty clear, straight-forward and easy to understand that a person is limited or no experience with scripting or automation can easily start working on it with great results.

    A lot of people I have spoken to about this tool treat it as a substitue for adsutil.vbs in IIS 6. I must say this tool is much more than just a substitute. The scenario I was working on, I had to enumerate all the application pool names on 250 web servers to make a report on the app pool usage analysis. At the surface this seems a pretty heavy task. Here's what I did:

    getcommand.bat
    This was my simple old school windows batch file that had commands that I actually needed to execute on the remote server to retrieve the application pool names. The contents of the .bat file were:

    @ECHO OFF
    hostname
    c:\windows\system32\inetsrv\appcmd.exe list apppool /text:name

    The bacth file couldnt have been simpler than that. By default "list apppool" command will enumerate the application pool names along with their current state, the .Net framework associated to them and few other properties. In my case I din't need those. Including /text:name will only output the name of the application pool.

    Note: Running the above command with /text:* will give you detailed information on the application pool, inclusive of the application pool password in plain text which is not available through GUI. It s good way to figure out in case you have any password issues going on, which in my case are abundant. :-)

    If you have any other method of running scripts or batch files in your environment, the above is all you need to get your work done.

    What I am doing below is integrating the batch file with a utility named psexec.exe from Sysinternals to run the above batch file remotely on the 200 odd servers I needed the data from.

    serverlist.txt
    This is a simple text file which contains server names on which we are planning to run our commands. You will have to place 1 servername on each line.

    psexec.exe
    This tool is free and included in the Sysinternal Suite. PSEXEC helps you run command on remote machines.

    apppool_names.txt
    This is going to be our output text file for collecting results.

    The last thing you need are Administrative priviliges on every machine you are planning to run this command on.

    Here's how you implement it:

    Open and command prompt with elevated priviliges and follow the below syntax:

    psexec.exe @serverlist -c commandtorun >>output

    in place of the file names its always good to place the complete path to the file. so in my case the command was:

    psexec.exe @c:\serverlist.txt -c c:\getcommand.bat >>c:\apppool_names.txt

    the -c in the above command will actually copy the batch file to every server and then execute it locally. You can also run just the appcmd command listed in getcommand.bat with psexec but then it will make things messy in the output because of which I made a batch file and included the hostname command to get the respective servername into the output...

    What would you like to automate on IIS?

    Related Resources:
    How To: AppCMD in IIS 7 - An Introduction
    How To: Using IIS 6.0 Command Line Utilities - Part 1
    How To: Using IIS 6.0 Command Line Utilities - Part 2
    WMI Integration in Batch File Scripting


    Hope this Helps.

  • How To: Use Microsoft.Web.Administration from Powershell

    Powershell has become a defacto scripting environment for a lot of  companies and rightly so considering its capabilities.
    However, not every place do we find all modules loaded into powershell as one would like for the ease of scripting. I faced a similiar situation wherein I wanted to perform few admin tasks on an IIS box and din't have the IIS powershell snap-in installed. Wish the server was Windows Server 2008 R2 (IIS module is out-of-the-box loaded). There are more than a couple ways which could handle the script I was aiming for. Nevertheless, I thought it was a great opportunity to check out this functionality.

    Essentially, I had to do the following:
    1. Get a particular website status. Lets say "MyWebSite" in this case.
    2. Start the website if it's in a stopped state.
    2. Next, go through all the application pools associated to the website.
    2. Check their status.
    3. Start the AppPools if stopped.
    4. Get all the information into a log file.
    We were going to run this script from a central repository, which, would execute the script locally on a pre-defined set of servers. However, this script can be easily modified to run using Powershell V2 remoting capabilities.

    Note: If you are not interested in the detailed working of the script just scroll down to get the complete script.

    To start with we need to load the assembly itself. This is how it's done:

    [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Web.Administration")

    Next is to create an instance of ServerManager class using which we can access the entire configuration. Developers would be familiar with the ServerManager class. Anyhow, more information is available here. Creating an instance is actually very as simple.

    $iis = New-Object Microsoft.Web.Administration.ServerManager

    That's it. Now, using this we can access information on IIS Sites, Applications, Worker Processes and much more. A simple example of a script would be to check the "MyWebSite" status and then act accordingly.

    Here's how you can get that:

                [string] $host2 = hostname
                Write-Host "Server name: $host2"


                 $site_name = $iis.sites["MyWebSite"]


               Write-Host "$site_name"


                $site_state = $iis.sites["MyWebSite"].state


                Write-Host "$site_state"

    Once we get the state of "MyWebSite", we can start the website if it is stopped.
           if ($iis.sites["MyWebSite"].state -eq "Stopped")
               {
                     $iis.sites["MyWebSite"].start()
                     Write-Host "WebSite Started"
                }

    Next, I wanted to do the same for all the Application Pools associated with "MyWebSite".

        foreach ($apppool in $site.applications)
            {
                    $appPoolName = $apppool.applicationpoolname
                    $apppoolobject = $iis.ApplicationPools[$appPoolName]
                          if ($apppoolobject.state -eq "Stopped")
                                {
                                      Write-Output $appPoolName $("is in stopped state... Attempting to Re-Start `n")
                                       [void]$apppoolobject.start()
                                           If ($apppoolobject.start() -eq "1")
                                                   {
                                                           # Write into log File
                                                    }
                                            Else
                                                   {
                                                        # Write into log file
                                                    }


                                 }
                           else
                                {
                                      Write-Output $("$appPoolName is already started `n `n")
                                }
             }
     
    In the above code once we get the application pool name all we do it try to start the AppPool. I have seen that sometimes even after we do a apppool.start() the application pool doesnt start properly, there we have an additional IfElse to check the app pool condition post-start.
     
    To run this script and collect the output into a log file, you would need to execute it in the following manner.
     
    .\IISStatus.ps1 Out-File IISStatus.log -append
     
    The output from your server will now be saved in IISStatus.log. I am using -append as we were collecting information from more than 100 servers. Also, if you are running this script for multiple server from a share location (My Case) i recommend giving a shared location for IISStatus.log as well. But make sure that the shared location is accessible over the network before you execute the script.
     
    Here's the whole script (IISStatus.ps1) and how the log file (IISStatus.log) looks like:
     
    $iis = New-Object Microsoft.Web.Administration.ServerManager
    [string] $host2 = hostname


    Write-Host "Server name: $host2"
    $site_name = $iis.sites["MyWebSite"]
    Write-Host "$site_name"
    $site_state = $iis.sites["MyWebSite"].state
    Write-Host "$site_state
    if ($site_state -eq "Stopped")
     {
        Write-Output $("WebSite is currently stopped... `n")
        Write-Output $("Starting the website ($site) `n")
         $iis.sites["MyWebSite"].start()
         Write-Output $("WebSite Started ($site) `n")
     }
    else
     {
         Write-Output $("Website ($site) is already started... Checking the Application Pools Now `n"
    }
    if($site.name -eq "MyWebSite" )
    {
        foreach ($apppool in $site.applications)
             {
                   $appPoolName = $apppool.applicationpoolname
                   $apppoolobject = $iis.ApplicationPools[$appPoolName]
                      if ($apppoolobject.state -eq "Stopped")
                          {
                               Write-Output $appPoolName $("is in stopped state... Attempting to Re-Start `n")
                                [void]$apppoolobject.start()
                                  If ($apppoolobject.start() -eq "1")
                                         {
                                              Write-Output $("$appPoolName has been re-started `n`n")
                                              Write-Output $("--------------------------------------------")
                                              Write-Output $("--------------------------------------------")
                                          }
                                   Else
                                         {
                                              Write-Output $("$appPoolName could not be re-started `n`n")
                                              Write-Output $("--------------------------------------------")
                                              Write-Output $("--------------------------------------------")
                                         }
                           }
                    else
                          {
                              Write-Output $("$appPoolName is already started `n `n")
                          }
           }
    }
    Write-Output $("--------------------------------------------")
    Write-Output $("--------------------------------------------")

    IISStatus.log:

    Server Name: Servername
    Site Name: MyWebSite
    Current Website Status: Started
    Website (MyWebSite) is already started... Checking the Application Pools Now
    AppPool1 is already started
    AppPool2 is already started
    --------------------------------------------
    --------------------------------------------


    Server Name: Servername
    Site Name: MyWebSite
    Current Website Status: Stopped
    WebSite is currently stopped...
    Starting the website (MyWebSite)
    Unknown
    WebSite Started (MyWebSite)
    AppPool1 is in stopped state... Attempting to Re-Start
    AppPool1 has been re-started
    --------------------------------------------
    --------------------------------------------
    AppPool2 is in stopped state... Attempting to Re-Start
    AppPool2 has been re-started
    --------------------------------------------
    --------------------------------------------
    --------------------------------------------
    --------------------------------------------

  • IIS Config Reference can now be downloaded

    I have been meaning to blog for quite sometime now but work has got me all tied up. However, this is something I just couldn't let go. Robert McMurray yesterday blogged about the availability of the IIS Config Reference in the form of Compiled Help Files. This means you can now read and learn the entire IIS congifuration offline. IIS Config Reference is a store of all IIS configuration parameters with examples of accessing those parameters from command line, Java Scripts, VB Scipts and the IIS API's. Its a great quick start place for IIS admins who like to automate their environments.

    The compiled Help files can be download from:

    Configuration Reference Help File for IIS 7.0
    Configuration Reference Help File for IIS 7.5

    It would be great if IIS and Powershell sample code examples were included as well.