尝试使用powershell脚本在IIS中创建网站

尝试使用powershell脚本在IIS中创建网站,powershell,iis,Powershell,Iis,我有以下脚本: $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

我有以下脚本:

$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"
我以如下方式执行:

create.ps1 "C:\inetpubyusufozturk.info" "www.yusufozturk.info" "yusufozturk.info”
我得到了以下错误:-

新项:找不到与参数名称匹配的参数 “绑定”。在C:\es\develope\ShareAspace\create.ps1:4 char:32 +新项目IIS:Sites$Description-Bindings(@{Protocol=“http”;BindingIn。。。 + ~~~~~~~~~ +CategoryInfo:InvalidArgument:(:)[New Item],参数BindingException +FullyQualifiedErrorId:NamedParameterNotFound,Microsoft.PowerShell.Commands.NewItemCommand


我是PS脚本新手。我不知道怎么了?还请告诉我如何通过power shell删除网站?

新项目
没有名为
-bindings
-physicalpath
的参数

我将使用
New-WebSite
cmdlet创建站点,并使用
Set-WebBinding
设置绑定


这些cmdlet位于WebAdministration模块中,如果您有权访问IIS:驱动器,则将使用该模块。请确保在提升的会话中使用此模块(作为管理员)。

此处记录了OP的实际操作:

在我的一个IIS服务器上

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

至于删除网站,只需使用Remove-website cmdlet

这是OP接受答案后的几年,但我只是想说明一下,我注意到,
新项目…-physicalPath
在我导入时停止工作(在使用来自的命令之后)这是在Windows2019 w/PS 5上进行的。

这里只是钓鱼,您正在开发的电脑上是否安装了iis?如果没有,请在安装了iis的电脑上尝试脚本。或者,在没有绑定的情况下创建网站,然后使用set-Webbinding或set-ItemProperty进行设置。我安装了iis。但是,如果我删除绑定并手动设置,则脚本的全部要点都是毫无意义的。我应该用脚本制作整个网站。显然,你会用脚本而不是手工制作。谢谢你的建议