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
}
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)
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
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?
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.
CoryD
13 Posts
Problem with New-Website
Aug 03, 2009 09:23 PM|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
CoryD
13 Posts
Re: Problem with New-Website
Aug 03, 2009 10:41 PM|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}
sergeia
73 Posts
Microsoft
Re: Problem with New-Website
Aug 03, 2009 11:43 PM|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
CoryD
13 Posts
Re: Problem with New-Website
Aug 03, 2009 11:46 PM|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.
CoryD
13 Posts
Re: Problem with New-Website
Aug 03, 2009 11:50 PM|LINK
I'm not on service pack 2, that might be the problem. Installing now.
sergeia
73 Posts
Microsoft
Re: Problem with New-Website
Aug 03, 2009 11:56 PM|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
CoryD
13 Posts
Re: Problem with New-Website
Aug 04, 2009 12:09 AM|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.
CoryD
13 Posts
Re: Problem with New-Website
Aug 04, 2009 12:10 AM|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
CoryD
13 Posts
Re: Problem with New-Website
Aug 04, 2009 12:17 AM|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:\>
CoryD
13 Posts
Re: Problem with New-Website
Aug 04, 2009 12:17 AM|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:\>