Powershell: List all IIS WebApplications (.net version, state, identity)

06 Mar 2013
March 6, 2013

Short powershell script to list all IIS Web Applications with the .net version, the state of the Web Application and the assigned user/identity.

And the output is a nice table:

WebAppName Version State UserIdentityType Username Password
SharePoint – 80 v2.0 Started SpecificUser demo\spservices pass@word1

 

Max Melcher
Follow me!

Max Melcher

Maximilian Melcher (MCSE, MCPD) is a Principal Consultant working at Alegri International Services in Munich, Germany. Max is a specialist in SharePoint technologies focused on search, social computing, web content management and collaboration. Max has led SharePoint implementations for Dax 30 companies since 2009.
Max’s free time is spent on twitter (@maxmelcher) mostly with a good coffee in his hands.
Max Melcher
Follow me!
Tags:
21 replies
  1. Sebastian Huppmann says:

    I can’t believe how often i need that one… 😀

    Reply
  2. kiquenet says:

    Maybe you can include Enable32BitAppOnWin64 property in your code sample.

    Note: (I think) Format-Table doesn’t works using PS Remoting.

    Reply
    • Max Melcher says:

      I wrote a code sample especially for you – it should not be that hard to add the parameter, right?
      Format-Table should work with ps remoting, I don’t see why it should not.

      Reply
  3. Matthew says:

    When I try to run this script, I get the following error:

    out-lineoutput : The object of type “Microsoft.PowerShell.Commands.Internal.Format.FormatStartData” is not valid or not
    in the correct sequence. This is likely caused by a user-specified “format-table” command which is conflicting with th
    e default formatting.
    + CategoryInfo : InvalidData: (:) [out-lineoutput], InvalidOperationException
    + FullyQualifiedErrorId : ConsoleLineOutputOutOfSequencePacket,Microsoft.PowerShell.Commands.OutLineOutputCommand

    In addition, it only lists the Name, Application Pool, Protocols and Physical Path rather than expected information. What am I missing?

    Reply
    • Max Melcher says:

      Matthew,

      strange one – I copied it to a Server 2008 and a Server 2012 – worked.
      From the error could you please try removing the format-table part of my script. The output will be messy but there error indicates that this is the faulty one.

      So long,
      Max

      Reply
      • Matthew says:

        Max…thank you for your prompt reply! I commented out the “format-table” line and the error went away, but the script is still not returning the expected data. Please see capture below:

        Just to run you through what I’ve done so far:

        – Copied and pasted code above into blank text file and saved at “test.ps1”
        – Opened PowerShell with admin privileges and navigated to saved file
        – Typed “.\test.ps1” and then ran it

        I’m just getting up to speed on PowerShell and scripting, so perhaps I’m missing something obvious?

        Reply
  4. Matthew says:

    Sorry…looks like the image didn’t post. Here is the URL:

    http://tinypic.com/r/2lavwox/8

    I had to cover up the actual data for privacy reasons, but you can see the headers listed.

    Best regards,

    Matthew

    Reply
    • Max Melcher says:

      Replace the “format-table” line with “select -property *” and see how that goes:
      $list | select -property *

      Reply
      • Matthew says:

        Max…I think we have made some progress!! I still get the initial listing of all sites at the beginning with the “Name,” “Application Pool,” “Protocols,” and “Physical Path” columns, but below that I now see the following:

        http://tinypic.com/r/259zxnb/8

        That gives me what I’m looking for, but is there a way to exclude the initial listing of sites? I don’t need that information. Also, how can I also output this to a text file?

        The reason we are trying to capture this information is that one of our main IIS servers mysteriously set ALL the Application Pools to 2.0 over our maintenance weekend. Luckily, we had a development server that we could use for reference to get things back up, but that’s not the case for all our servers. I’m wanting to use a script like this as a scheduled task to output a listing of current sites and version numbers in case it happens in the future.

        Thank you so much for your help this far!!

        Matthew

        Reply
  5. Sravan says:

    Could you please explain on what basis array object is choosen for $list and hashtable for $item.

    Reply
    • Max Melcher says:

      Sravan, the list is just an array without a type. The item is a hashset / anonymous object so I can assign properties I want and need.

      Cheers!
      Max

      Reply
  6. Thennarasu says:

    Thanks for the Script,

    I would need the Script to find all these details for the Remote IIS Server.

    Also, I am getting the below error , When I execute this is on the local IIS Server.

    The object of type “Microsoft.PowerShell.Commands.Internal.Format.FormatStartData” is not valid or not in the correct sequence. This is likely caused by a user-specified “format-ta
    ble” command which is conflicting with the default formatting.
    + CategoryInfo : InvalidData: (:) [out-lineoutput], InvalidOperationException
    + FullyQualifiedErrorId : ConsoleLineOutputOutOfSequencePacket,Microsoft.PowerShell.Commands.OutLineOutputCommand

    Reply
  7. Thennarasu says:

    Hi Max,

    I am getting the below error when I run the below script. Pls help me to get the website details on a remote server

    $servers = (Get-Content servers.txt)
    $count =
    $today = Get-Date

    Write-Host “”
    Write-Host “Today the date is ‘$today'”

    # Verify IIS Settings

    foreach($vm in $servers)
    {
    Enter-PSSession $vm
    Import-Module WebAdministration
    # $vm = $servers
    $CompDetails=Get-WmiObject -Class Win32_operatingsystem -ComputerName $vm
    #$HostName=$CompDetails.CSName
    $OSVersion=$CompDetails.Caption
    $Desc=$CompDetails.Description
    #$description = $desc.Description
    #$bios = Get-WmiObject -Class Win32_BIOS
    #gwmi win32_bios
    #$appPoolStatus = Invoke-Command -ComputerName $vm
    $IISServicestatus = get-wmiobject Win32_Service -ComputerName $vm -Filter “name=’IISADMIN'”
    $iisversion = get-itemproperty HKLM:\SOFTWARE\Microsoft\InetStp\ | select versionstring
    #$Websitename = Get-Website
    Write-Host “Computer Name : $vm”
    Write-Host “OS Version : $OSVersion”
    Write-Host “Computer Description : $desc”

    if($IISServicestatus.State -eq “Running”)
    {
    Write-Host “”
    Write-Host “IIS is running on $vm”
    Write-Host “”
    Write-Host $iisversion

    }
    else
    {
    Write-Host “IIS is not running on $vm”
    }

    Write-Host “Website Details”
    Get-Website

    Exit-PSSession

    }

    Error msg:

    Today the date is ’07/24/2014 20:57:14’
    Enter-PSSession : Connecting to remote server failed with the following error message : The WS-Management service cannot process the request. This user is allowed a maximum number
    of 5 concurrent shells, which has been exceeded. Close existing shells or raise the quota for this user. For more information, see the about_Remote_Troubleshooting Help topic.
    At D:\Thenna\test.ps1:14 char:22
    + Enter-PSSession <<<< $vm
    + CategoryInfo : InvalidArgument: (RMPAU901MELM001.ECORPTST.ANZ.COM:String) [Enter-PSSession], PSRemotingTransportException
    + FullyQualifiedErrorId : CreateRemoteRunspaceFailed

    Reply
  8. Thennarasu says:

    Hi Max,

    The script is not providing the ouyput as you have mentioned, its just providing the output as below
    Name Application Pools Protocols PhysicalPath

    Please check this script and let us know the changes to be done from my end.

    Reply
    • Max Melcher says:

      Hi Thennarasu,

      I cant imagine that – the script outputs “WebAppName”, “Version”, “State”, “UserIdentityType”, “Username”, “Password”

      Can you provide a screenshot?

      Cheers!
      Max

      Reply
  9. Dipti Chhatrapati says:

    Hi Max,

    i am so GLAD to see your solution , it has really gave me smooth breath 🙂

    However, I would like to know – how can I execute the same script for remote server ? Is there any possibility ?

    Your help will be much appreciated !

    Thanks and Regards,

    Reply
  10. Sonakshi says:

    Hi Max,

    This script is very helpful. But how can we see the same properties which are now showing by this script in similar format for a specific app pool ?

    Your help will be much appreciated !

    Thanks .

    Reply

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.

Close