Powershell script to export IIS website details [Answered]RSS

2 replies

Last post Dec 22, 2015 11:25 AM by Mateiash

  • Powershell script to export IIS website details

    Nov 16, 2015 03:40 AM|aurigomsdn|LINK

    <div class="post-text" itemprop="text">

    Hi,

    I need to extract all the website details created in our IIS server with the following details. As we have more than 80 sites created in our IIS server, I am searching for an easier way to export these details.

    details required :

    • Website Name
    • Bindings
    • State
    • DB Server name [mapped in connection string]
    • DB Name [mapped in connection string]

    I am able to extract all the details except DB related available in connection strings using get-website cmdlet. Requesting your help if you know any better way to extract all the information under single file.

    Thanks,

    Raghavendra.

    </div>
  • Re: Powershell script to export IIS website details

    Nov 16, 2015 10:04 PM|Pengzhen Song - MSFT|LINK

    Hi,

    You can try using get-webconfiguration and get-webconfigurationproperty cmdlets to get connection string and then extract DBname. For more information, please refer to the document:

    http://blogs.iis.net/jeonghwan/examples-of-iis-powershell-cmdlets

    https://technet.microsoft.com/en-us/library/hh867890(v=wps.630).aspx

    And the similar discussion:

    Import-Module WebAdministration
    
    Get-WebApplication | `
    ForEach-Object {
    
    $webConfigFile = [xml](Get-Content "$($_.PhysicalPath)\Web.config")
    Write-Host "Web Application: $($_.path)"
    foreach($connString in $webConfigFile.configuration.connectionStrings.add)
    {
      Write-Host "Connection String $($connString.name): $($connString.connectionString)"
      $dbRegex = "((Initial\sCatalog)|((Database)))\s*=(?<ic>[a-z\s0-9]+?);"
      $found = $connString.connectionString -match $dbRegex
      if ($found)
      {
       Write-Host "Database: $($Matches["ic"])"
      }
    
    }
    Write-Host " "
    }

    http://stackoverflow.com/questions/7053595/get-dbname-from-multiple-web-config-files-with-powershell

    Hope it can help you.

    We are trying to better understand customer views on social support experience. Click HERE to participate the survey.
    Thanks!
  • Re: Powershell script to export IIS website details

    Dec 22, 2015 11:25 AM|Mateiash|LINK

    I have 360 Websites on my IIS, and when I am trying to export to a file (txt or csv), I have just 220 websites listed

    There is a buffer limit for appcmd.exe command?

    Thanhks