We are excited to announce that the IIS.NET Forums are moving to the new Microsoft Q&A experience. Learn more >

Error Creating New IIS site [Answered]RSS

8 replies

Last post Jun 20, 2011 09:38 PM by Lloydz

  • Error Creating New IIS site

    Jun 10, 2011 09:50 AM|webguynj|LINK

    I am getting an error creating a website with Powershell witht he New-Item command

    New-Item : Index was outside the bounds of the array.
    At C:\Users\administrator.ACME\Documents\CreateSite.ps1:22 char:9
    + New-Item <<<<  iis:\Sites\$sitename -bindings @{protocol="http";bindingInformation=":80:www.$dns"} -physicalPath c:\inetpub\ecomroot\$siteName
        + CategoryInfo          : NotSpecified: (:) [New-Item], IndexOutOfRangeException
        + FullyQualifiedErrorId : System.IndexOutOfRangeException,Microsoft.PowerShell.Commands.NewItemCommand

    This is only happening if there are no Web sites defined in IIS.  If I create a site manually the New-Item command works fine.

  • Re: Error Creating New IIS site

    Jun 12, 2011 07:20 AM|steve schofield|LINK

    Is the Default Website on the server?  Or has this been removed?

    Steve Schofield
    Windows Server MVP - IIS
    http://iislogs.com/steveschofield
    http://www.IISLogs.com
    Log archival solution
    Install, Configure, Forget

  • Re: Error Creating New IIS site

    Jun 14, 2011 10:15 AM|webguynj|LINK

    We are planning on removing the default site in our IIS installation script.  The intent is that for PCI compliance everything is supposed to be clean before sites are set up.
  • Re: Error Creating New IIS site

    Jun 16, 2011 03:35 AM|Lloydz|LINK

    Hi,

    Could you please post the command you use?
    As the error indicates, it is mostly like that the index you referenced does not exist.

    Thanks.

     

  • Re: Error Creating New IIS site

    Jun 16, 2011 09:44 AM|webguynj|LINK

    Here is the command that we are using to create the new site:

    # Create website with core binding
    New-Item iis:\Sites\$sitename -bindings @{protocol="http";bindingInformation=":80:www.$dns"} -physicalPath c:\inetpub\ecomroot\$siteName

  • Re: Error Creating New IIS site

    Jun 16, 2011 09:30 PM|Lloydz|LINK

    Weird enough, the command should work. Could you please elaborate the content of $sitename, or post the entire script here? Maybe we could find some clues in it.

    Thanks.

  • Re: Error Creating New IIS site

    Jun 17, 2011 10:20 AM|webguynj|LINK


    import-module webAdministration

    $appPoolUserName = "ecotco\AspAppAccount"

    #Get user input
    $dns      = read-host "Enter the cononical DNS   :"
    $siteName = read-host "Enter the Site Description:"

    $appPoolID = Read-Host -prompt "Password for $AppPoolUsernme :" -AsSecureString
    $appPoolPassword = ConvertTo-PlainText $appPoolID

    # Create Directory for site
    New-Item C:\inetPub\ecomRoot\$siteName -type Directory

    # Create Application Pool
    New-Item IIS:\AppPools\$siteName
    # Set Application Pool Itentity
    Set-ItemProperty iis:\apppools\$siteName -name processModel -value @{userName="ecommerce\AspAppAccount";password="$appPoolPassword";identitytype=3}
    add-webconfiguration "/system.applicationHost/applicationPools/add[@name='$siteName']/recycling/periodicRestart/schedule" -value (New-TimeSpan -h 2 -m 00)

    # Create website with core binding
    New-Item iis:\Sites\$sitename -bindings @{protocol="http";bindingInformation=":80:www.$dns"} -physicalPath c:\inetpub\ecomroot\$siteName
    # Assign Application Pool
    Set-ItemProperty IIS:\sites\$siteName -name applicationPool -value "$siteName"

    # Add additional cononical binding
    New-ItemProperty IIS:\sites\$sitename -name bindings -value @{protocol="http";bindingInformation=":80:$dns"}

    Function ConvertTo-PlainText( [security.securestring]$secure ) {
     $marshal = [Runtime.InteropServices.Marshal]
     $marshal::PtrToStringAuto( $marshal::SecureStringToBSTR($secure) )
     }
     

  • Re: Error Creating New IIS site

    Jun 19, 2011 11:02 PM|Lloydz|LINK

    Hi, I can reproduce this issue when there's no site hosted on the server. We are analyzing this issue now and will let you know as soon as we have any process. Thanks.
  • Re: Error Creating New IIS site

    Jun 20, 2011 09:38 PM|Lloydz|LINK

    Hi Webguynj,

    After a short discussion of this issue, it appears to be a known product issue. To address the issue, please add “-id 1” when you execute the new-item cmdlet if there is no site.

    Thanks.