尝试通过Powershell脚本在IIS中创建网站

问题描述 投票:0回答:2

我有以下脚本:

$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:找不到与参数名称'Bindings'匹配的参数。在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

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

powershell iis
2个回答
1
投票

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

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

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


0
投票

实际上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

© www.soinside.com 2019 - 2024. All rights reserved.