2

I have the following script:

$Logdir = $args[0]
$Description = $args[1]
$Domain = $args[2]
New-Item IIS:Sites$Description -Bindings (
    @{Protocol="http"; BindingInformation="*:80:$Domain"},
    @{Protocol="http"; BindingInformation="*:80:www.$Domain"}
) -PhysicalPath "$LogDirhttp"

I executed it as:

create.ps1 "C:\inetpubyusufozturk.info" "www.yusufozturk.info" "yusufozturk.info”

I got following error:-

New-Item : A parameter cannot be found that matches parameter name 'Bindings'. At C:\es\develop\ShareAspace\create.ps1:4 char:32 + New-Item IIS:Sites$Description -Bindings (@{Protocol="http";BindingIn ... + ~~~~~~~~~ + CategoryInfo : InvalidArgument: (:) [New-Item], ParameterBindingException + FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.Commands.NewItemCommand

I'm new in PS scripting. I don't know what is wrong? Also please inform me how to delete a website by power shell?

3
  • just fishing here, do you have iis installed on the pc you are developing on? if not try the script on a pc with iis. alternatively create the site without the bindings and set them afterwards with Set-Webbinding or Set-ItemProperty Commented Jan 1, 2018 at 18:17
  • I have iis installed. But if I remove the bindings and set it by hand, then the whole points of scripting is kind of pointless. I should make the whole website by the script Commented Jan 1, 2018 at 18:34
  • Obviously you would do it in the script and not by hand. Commented Jan 1, 2018 at 22:47

3 Answers 3

4

New-Item doesn't have parameters named -bindings or -physicalpath.

I would use the New-WebSite cmdlet to create the site and the Set-WebBinding to set the bindings.

These cmdlets are in the WebAdministration module, which you're using if you have access to the IIS: drive. Be sure to use this module in an elevated session (as administrator).

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the suggestions
2

Actually what the OP is doing, is documented here:

https://learn.microsoft.com/en-us/iis/manage/powershell/powershell-snap-in-creating-web-sites-web-applications-virtual-directories-and-application-pools

On one of my IIS servers...

Import-Module -Name WebAdministration

Get-Website | Select Name,ID,State,PhysicalPath

name             id state   physicalPath                 
----             -- -----   ------------                 
Default Web Site  1 Started %SystemDrive%\inetpub\wwwroot
kcd               2 Started C:\inetpub\kcd               



New-Item iis:\Sites\MyTestSite -bindings @{protocol="http";bindingInformation=":80:MyTestSite"} -physicalPath c:\MyTest

Name             ID   State      Physical Path                  Bindings                                                         
----             --   -----      -------------                  --------                                                         
MyTestSite       3    Started    c:\MyTest                      http :80:MyTestSite                                              



Get-Website | Select Name,ID,State,PhysicalPath

name             id state   physicalPath                 
----             -- -----   ------------                 
Default Web Site  1 Started %SystemDrive%\inetpub\wwwroot
kcd               2 Started C:\inetpub\kcd               
MyTestSite        3 Started c:\MyTest   


Get-WebBinding 

protocol bindingInformation            sslFlags
-------- ------------------                --------
http     *:80:                                    0
http     192.168.1.3:80:kcd....                   0
http     :80:MyTestSite                           0

As for deleting the website, just use the Remove-Website cmdlet

Comments

0

This is years after the OP has accepted an answer, but I just wanted to put it out there that I noticed that New-Item ... -physicalPath stopped working for me when I imported IISAdministration (after using commands from WebAdministration.) This was on Windows2019 w/ PS 5.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.