Problem with New-Website [Answered]RSS

22 replies

Last post Dec 06, 2012 09:07 AM by supi007

  • Problem with New-Website

    Aug 03, 2009 05:23 PM|CoryD|LINK

    I've written the following script to add websites stored in a directory structure that is as follows

    d:\Websites\google.com\Site\ 

    where \Site is the virtual root of the website.

    Whenever I run the script, I get
    New-Item : Index was outside the bounds of the array

    And I don't remember how to get the stack trace to paste here but when I did it yesterday, it was a problem in the method GenerateSiteID or something similarly named.

    $websiteDirs = Get-ChildItem -Path "d:\Websites"

    foreach( $dir in $websiteDirs ) {    
        $webRoot = join-path $dir.FullName Site
        New-Website -name $dir.Name -physicalPath $webRoot -HostHeader $dir.Name
    }

     

    powerShell IIS7

  • Re: Problem with New-Website

    Aug 03, 2009 06:41 PM|CoryD|LINK

    Any help you can provide would be great.  I'm running windows server 2008 and when I uninstalled IIS I could run the script, then I could install IIS7 and the changes would be made, this is unacceptable, we must be able to run our server and still make configuration changes!  Here is the stack trace:


    System.IndexOutOfRangeException: Index was outside the bounds of the array.
       at Microsoft.IIs.PowerShell.Framework.SiteFactory.GenerateNewSiteIDIncremental(NodeIndexedCollection coll)
       at Microsoft.IIs.PowerShell.Framework.SiteFactory.GenerateSiteID(NodeIndexedCollection coll,String siteName)
       at Microsoft.IIs.PowerShell.Framework.SiteFactory.AddSiteFromDynamicParameters(INamespaceNode parent, ConfigurationElementCollection coll, String name, NewSiteDynamicParameters inputParameters, Boolean recurse, Boolean force, TypeManager tm, CmdletProvider provider)
       at Microsoft.IIs.PowerShell.Framework.SiteFactory.CreateInstance(String name, String typeName, INamespaceNode parent, Object dynamicParameters, Object newObject, Boolean force, Boolean recurse, TypeManager tm, CmdletProvider provider)
       at Microsoft.IIs.PowerShell.Framework.TypeManager.CreateInstance(String nodeTag, INamespaceNode parent, String nodeName, Object dynamicParameters, Boolean force, Boolean recurse, Object newObject, CmdletProvider provider)
       at Microsoft.IIs.PowerShell.Provider.ConfigurationProvider.NewItem(String path, String itemTypeName, Object newItemValue)
       at System.Management.Automation.Provider.ContainerCmdletProvider.NewItem(String path, Stringtype, Object newItemValue, CmdletProviderContext context)
       at System.Management.Automation.SessionStateInternal.NewItemPrivate(CmdletProvider providerInstance, String path, String type, Object content, CmdletProviderContext context)

    CategoryInfo          : NotSpecified: (:) [New-Item], IndexOutOfRangeException
    System.IndexOutOfRangeException,Microsoft.PowerShell.Commands.NewItemCommand
    InvocationInfo        : System.Management.Automation.InvocationInfo
    PipelineIterationInfo : {0, 1}

  • Re: Problem with New-Website

    Aug 03, 2009 07:43 PM|sergeia|LINK

    Cory, which version of PowerShell are you running? I just tried this on Windows Server 2008 R2 (which has PowerShell v2.0 but the same exactly IIS snapin):

    PS I:\websites> $websiteDir = dir i:\websites
    PS I:\websites> $websiteDir


        Directory: I:\websites


    Mode                LastWriteTime     Length Name
    ----                -------------     ------ ----
    d----          8/3/2009   4:34 PM            bar
    d----          8/3/2009   4:34 PM            baz
    d----          8/3/2009   4:34 PM            foo
    d----          8/3/2009   4:35 PM            google.com


    PS I:\websites> foreach ($dir in $websiteDir) {
    >> $webRoot = join-path $dir.FullName Site
    >> New-website -name $dir.name -physicalpath $webroot -hostheader $dir.Name
    >> }
    >>

    Name             ID   State      Physical Path                  Bindings
    ----             --   -----      -------------                  --------
    bar              3    Started    I:\websites\bar\Site           http *:80:bar
    baz              4    Started    I:\websites\baz\Site           http *:80:baz
    foo              5    Started    I:\websites\foo\Site           http *:80:foo
    google.com       6    Started    I:\websites\google.com\Site    http *:80:google.com
     

     and I don't see any problems. Could you please repeat those actions from command line?

     

    Thanks,

    --Sergei

     

  • Re: Problem with New-Website

    Aug 03, 2009 07:46 PM|CoryD|LINK

    Are you asking me to run them again?  I'll go ahead and do it.  And check my version number on WinServer2008 as well.

  • Re: Problem with New-Website

    Aug 03, 2009 07:50 PM|CoryD|LINK

     I'm not on service pack 2, that might be the problem.  Installing now.

  • Re: Problem with New-Website

    Aug 03, 2009 07:56 PM|sergeia|LINK

    I was asking you to run your commands line by line, as I did. Sometimes in the script variables are assigned not the way you expect them to be.

    My understanding is that you use release version of IIS snapin, right?

     

    Thanks,

    Sergei

  • Re: Problem with New-Website

    Aug 03, 2009 08:09 PM|CoryD|LINK

     I have tried it manually line by line before with the same error message, even doing it interactively it failed after I gave it the name of the website.  I should have sp2 installed momentarily so hopefully that will fix it.

  • Re: Problem with New-Website

    Aug 03, 2009 08:10 PM|CoryD|LINK

    I'm not sure what you mean by release version. I downloaded mine here:
    http://www.iis.net/downloads/default.aspx?tabid=34&g=6&i=1664

  • Re: Problem with New-Website

    Aug 03, 2009 08:17 PM|CoryD|LINK

     PS IIS:\> New-Website -Name Blah
    New-Item : Index was outside the bounds of the array.
        + CategoryInfo          : NotSpecified: (:) [New-Item], IndexOutOfRangeException
        + FullyQualifiedErrorId : System.IndexOutOfRangeException,Microsoft.PowerShell.Commands.NewItemCommand

    PS IIS:\>

  • Re: Problem with New-Website

    Aug 03, 2009 08:17 PM|CoryD|LINK

     PS IIS:\> New-Website -Name Blah
    New-Item : Index was outside the bounds of the array.
        + CategoryInfo          : NotSpecified: (:) [New-Item], IndexOutOfRangeException
        + FullyQualifiedErrorId : System.IndexOutOfRangeException,Microsoft.PowerShell.Commands.NewItemCommand

    PS IIS:\>

  • Re: Problem with New-Website

    Aug 03, 2009 08:20 PM|CoryD|LINK

     Installed Service Pack 2 and it is still not working, entering in line by line doesn't work either, I get the same result.  However again, when IIS 7 is not installed but the snap in IS.  I can run the commands and then after I run them if I install IIS7, the commands will have taken effect!  I don't have a clue whats going on wrong here.  How are you using the WebAdministration module, I'm clicking on the shortcut that installing the IIS 7 snap in provided...Is that the problem? 

  • Re: Problem with New-Website

    Aug 04, 2009 12:09 AM|sergeia|LINK

    Corey, if IIS is not installed, Powershell snapin cannot be installed, or will not work -- because configuration system is not available. So there is something unusual with your setup.

    I cannot reproduce your issue on any of my machines, I will ask our tester tomorrow to look to this . Meanwhile you could try a workaround -- new-website command takes site ID as a parameter, try passing it and see if it will help. Another workaround is to set Registry key parameter that will switch site ID generation from sequental mode to random, i.e. ID will be auto-generated from site name. Registry key name is

    HKLM\SOFTWARE\Microsoft\InetMgr\Parameters

    parameter name is "IncrementalSiteIDCreation". If it is 0 -- randomnumber will be used. Both these workarounds will avoid code path that fails on you. Let me know if it will help.

    Do you have any web sites on your machine? Could you create site using other tools, like our GUI InetMgr? If you could, do you see site list in PowerShell, using command dir IIS:\sites?

     

    Thanks,

    Sergei

  • Re: Problem with New-Website

    Aug 04, 2009 11:30 AM|CoryD|LINK

    The registry change seems to have allowed my script to run.  However, I would still like it fixed the other way, and I would like to understand what is going wrong so I can fix similar problems like this on my own in the future.

    About my initial installation: I installed the webserver role, then I Installed the snap-in; I tried my script and the New-Website call, it worked the first time, then I was playing with some other IIS 7 features and powershell crashed, I sent the the report to MS, and then it wouldn't work from then on.  Then I uninstalled the web server role, and I noticed that the IIS 7 snap in for posh was still there, so I tried my script, it worked!  Then I reinstalled the web server role and when it was finished and the web sites had been loaded into it by my script.  Then I deleted the sites, and tried my script while the role was installed, I then received the same message I posted above.  All of this made me very uneasy and uncomfortable with the system as I was not certain what was going on.  Hope that clears things up for you.  I still am operating under the assumption that something is wrong with the server installation re-loading the box is possible but only as a last-last resort.

    However your registry hack has for the moment allowed me to continue reloading web sites to the machine, cheers!

  • Re: Problem with New-Website

    Aug 04, 2009 11:32 AM|CoryD|LINK

     I'm going to see if I can grab that crash report from the server.

  • Re: Problem with New-Website

    Aug 04, 2009 10:22 PM|CoryD|LINK

    This occurred before any of the Index bounds errors started happening, don't know if it is relevant or what, but I thought I'd post it.

     Provider Health: Dynamic parameters for NewItem cannot be retrieved from the 'WebAdministration' provider for path '\\TEST-ALPHA\'. Item type cannot be resolved from parent path \\TEST-ALPHA
    Parameter name: path.

    Details:
        ProviderName=WebAdministration
        ExceptionClass=ProviderInvocationException
        ErrorCategory=InvalidOperation
        ErrorId=NewItemDynamicParametersProviderException
        ErrorMessage=Dynamic parameters for NewItem cannot be retrieved from the 'WebAdministration' provider for path '\\TEST-ALPHA\'. Item type cannot be resolved from parent path \\TEST-ALPHA
    Parameter name: path

        Severity=Warning

        SequenceNumber=246

        HostName=ConsoleHost
        HostVersion=1.0.0.0
        HostId=c7f5127c-caae-4276-af7d-481c81e36c89
        EngineVersion=1.0.0.0
        RunspaceId=e06cac5c-151d-4f43-b055-6188ad6b51de
        PipelineId=82
        CommandName=
        CommandType=
        ScriptName=
        CommandPath=
        CommandLine=

  • Re: Problem with New-Website

    Aug 04, 2009 10:42 PM|CoryD|LINK

     I still am very interested in what is causing my powershell installation to misbehave.  I have another symptom that may help in the diagnosis.  When I run the SQL Server 2008 powershell and I type Get-Command so I can see all the cmdlets, it errors out giving:

    Get-Command : Object reference not set to an instance of an object.
    At line:1 char:12
    + Get-Command <<<<
        + CategoryInfo          : NotSpecified: (:) [Get-Command], NullReferenceEx
       ception
        + FullyQualifiedErrorId : System.NullReferenceException,Microsoft.PowerShe
       ll.Commands.GetCommandCommand
     

  • Re: Problem with New-Website

    Aug 05, 2009 12:36 AM|sergeia|LINK

    Corey, I opened bug with your findings for this issue. As soon as we will be able to reproduce this problem, I will have more information.

    Thanks,

    Sergei

  • JeongHwan JeongHwan

    50 Posts

    Microsoft

    Moderator

    Re: Problem with New-Website

    Aug 05, 2009 07:11 PM|JeongHwan|LINK

    We were able to reproduce your issue. It is a product issue and we will fix it some day in future. The issue we found is that if there is no web sites, the new-website cmdlet does not work with showing the error message. Please let me know if this is not your case and we will investigate more.

    FYI, another work-around regarding the site id is to use -id parameter as the following (I have added -id parameter into your script source):

    $websiteDirs = Get-ChildItem -Path "d:\Websites"
    foreach( $dir in $websiteDirs ) {   
        $webRoot = join-path $dir.FullName Site

        ### set id with the biggest id value of existing web sites + 1
        $id = (dir iis:\sites | foreach {$_.id} | sort -Descending | select -first 1) + 1
        New-Website -name $dir.Name -physicalPath $webRoot -HostHeader $dir.Name -id $id
    }


     

    Jeong Hwan Kim
  • Re: Problem with New-Website

    Jul 26, 2010 01:03 PM|kcb263|LINK

    Came across this thread while researching a problem I was having. This answered my question. Apparently, the bug still exists as of a year after the response, but it is good to know that by simply adding "-ID xxx" it can be circumvented. Thanks for the answer JeongHwan.
  • Re: Still a BUG with New-Website

    Mar 14, 2011 03:00 PM|AWOMS|LINK

    ===== 

    NAME
        New-Website

    SYNOPSIS
        Creates a new IIS Web site.

    SYNTAX
        New-Website [-Name] <String> [-Id <UInt32>] [-Port <UInt32>] [-IPAddress <String>] [-HostHeader <String>] [-PhysicalPath <St
        String>] [<CommonParameters>]


    DESCRIPTION
        Creates a new IIS Web site.


    PARAMETERS
        -Name <String>
            The name of the new site to create.

            Required?                    true
            Position?                    1
            Default value
            Accept pipeline input?       true (ByPropertyName)
            Accept wildcard characters?  false

        -Id <UInt32>
            The ID to use for the new site.

            Required?                    false
            Position?                    named
            Default value
            Accept pipeline input?       true (ByPropertyName)
            Accept wildcard characters?  false

    =====

    I too was not able to get 'New-Website' cmdlet to work without specifiying an ID even though the Get-Help says Id is not required.

  • Re: Problem with New-Website

    Mar 27, 2012 03:50 PM|AppWorksDev|LINK

    Hi, I experienced the same problem. It occurs when you try to create a website while there are 0 existing websites. As soon as I added a "Default" website the command worked fine. Thanks,
  • Re: Problem with New-Website

    May 11, 2012 06:47 AM|tweenet|LINK

    This problem does not occur when using Windows Server 2008 Server-Core, removing all web sites and then creating new ones in a script works fine, using the same script in the full GUI version of Windows fails as described above.
    Peter Hahndorf
  • Re: Problem with New-Website

    Dec 06, 2012 09:07 AM|supi007|LINK

    Hi,

    I also got this message back and it is truthfully annoying something. My advice checking whether do you have already existing Web Sites.

    (Ctrl+c & Ctrl+v the following code)

    Import-Module WebAdministration;$a=Get-Website;If($a -eq $Null){Write-Host "Whether my variable is empty or not?" -ForegroundColor White;Write-Host "Yeah, it's definately a null-valued variable." -ForegroundColor Yellow}Else{Write-Host "Whether my variable is empty or not?" -ForegroundColor White;Write-Host "Nope, There is something in there." -ForegroundColor Green}

    If you are getting nothing back it means that you do not have existing site. In this case you must use the -Id parameter and it has to have a valid value. For instance:

    New-Website -Name Blah -Id 1 -PhysicalPath C:\inetpub\wwwroot

    This helped me.

    If you have already have sites you shouldn't use the -Id parameter because the script will increase the number and this number will be assigned to the newly created site.

    I hope this helps.

    Cheers (sry for typos)