【问题标题】:Trying to create a website in IIS by Power Shell script尝试通过 Powershell 脚本在 IIS 中创建网站
【发布时间】:2018-01-01 17:11:20
【问题描述】:

我有以下脚本:

$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”

我收到以下错误:-

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

我是 PS 脚本的新手。我不知道出了什么问题?另外请告诉我如何通过power shell删除网站?

【问题讨论】:

  • 只是在这里钓鱼,您正在开发的PC上安装了iis吗?如果没有在带有 iis 的电脑上尝试脚本。或者创建没有绑定的站点,然后使用 Set-Webbinding 或 Set-ItemProperty 设置它们
  • 我已经安装了 iis。但是,如果我删除绑定并手动设置它,那么脚本的全部要点就毫无意义了。我应该通过脚本制作整个网站
  • 显然你会在脚本中而不是手动完成。

标签: powershell iis


【解决方案1】:

New-Item 没有名为 -bindings-physicalpath 的参数。

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

这些 cmdlet 位于 WebAdministration 模块中,如果您有权访问 IIS: 驱动器,则可以使用该模块。请务必在提升的会话中使用此模块(以管理员身份)。

【讨论】:

  • 感谢您的建议
【解决方案2】:

实际上 OP 正在做什么,记录在这里:

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

在我的一台 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

【讨论】:

    【解决方案3】:

    这是在 OP 接受答案多年后,但我只是想把它放在那里,我注意到当我导入 IISAdministrationNew-Item ... -physicalPath 停止为我工作(在使用来自 WebAdministration 的命令之后。)这是在带有 PS 5 的 Windows2019 上。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-10-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-28
      相关资源
      最近更新 更多