WebAdministration: Creating a new site fails in Server 2012, works in Server 2008 & Win7 - by wbradney

Status : 


Sign in
to vote
ID 789540 Comments
Status Active Workarounds
Type Bug Repros 1
Opened 6/5/2013 5:45:10 AM
Access Restriction Public


We have the following script block that we've been using for a while (on Windows Server 2008 and Windows 7) to create sites in IIS:

Import-Module WebAdministration
Set-Location IIS:/
Get-ChildItem Sites
$bindings = @{protocol="http";bindingInformation="*:8282:"},@{protocol="net.tcp";bindingInformation="4343:*"},@{protocol="net.pipe";bindingInformation="*"}
$site = New-Item Sites\site -bindings $bindings

The Get-ChildItem call lists the existing sites correctly. "site" does not yet exist.
When we run it on Windows Server 2012, we get:

New-Item : Length cannot be less than zero.
Parameter name: length
At C:\Users\Administrator\test.ps1:5 char:9
+ $site = New-Item Sites\site -bindings $bindings
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [New-Item], ArgumentOutOfRangeException
    + FullyQualifiedErrorId : Length cannot be less than zero.
Parameter name: length,Microsoft.PowerShell.Commands.NewItemCommand
Sign in to post a comment.
Posted by wbradney on 4/3/2014 at 9:52 AM
I can confirm that the bug is with the setting of the bindings with New-Item - if you try to add more than one binding it fails in PS 3.0, but works in PS 2.0.
If you add a single binding via New-Item it works in 3.0, so you can get multiple bindings in by doing the following (ie add a single binding and the replace all the bindings):

     $httpBinding = @{protocol="http";bindingInformation="*:8282:"}
     $site = New-Item IIS:\Sites\$siteName -PhysicalPath $path -Bindings $httpBinding
     Set-ItemProperty IIS:\Sites\$siteName -Name bindings -Value (@{protocol="http";bindingInformation="*:8282:"},@{protocol="net.tcp";bindingInformation="4343:*"},@{protocol="net.pipe";bindingInformation="*"})
Posted by wbradney on 4/1/2014 at 1:16 PM
Seriously? No feedback on this? Seems like a pretty fundamental bug.