简体   繁体   English

在 IIS 中创建网站的 Powershell 脚本

[英]Powershell script to create website in IIS

Can someone help me with creation of website from power shell.Script i have written below is not working .有人可以帮我从 power shell 创建网站吗。我在下面写的脚本不起作用。

Import-Module WebAdministration

#navigate to the app pools root
cd IIS:\AppPools\

#check if the app pool exists
if (!(Test-Path $iisAppPoolName -pathType container))
{
    #create the app pool
    $appPool = New-Item $iisAppPoolName
    $appPool | Set-ItemProperty -Name "managedRuntimeVersion" -Value $iisAppPoolDotNetVersion
}

#navigate to the sites root
cd IIS:\Sites\

#check if the site exists
if (Test-Path $iisAppName -pathType container)
{
    return
}

#create the site
$iisApp = New-Item $iisAppName -bindings @{protocol="http";bindingInformation=":80:" + $iisAppName} -physicalPath $directoryPath
$iisApp | Set-ItemProperty -Name "applicationPool" -Value $iisAppPoolName

For me New-Item did not work, I had to use New-WebSite like this:对我来说 New-Item 不起作用,我不得不像这样使用 New-WebSite:

$SiteName = "MySite"
$HostName = "localhost"
$SiteFolder = Join-Path -Path 'C:\inetpub\wwwroot' -ChildPath $SiteName

New-WebSite -Name $SiteName -PhysicalPath $SiteFolder -Force
$IISSite = "IIS:\Sites\$SiteName"
Set-ItemProperty $IISSite -name  Bindings -value @{protocol="https";bindingInformation="*:443:$HostName"}

Then start the Website:然后启动网站:

Start-WebSite -Name $SiteName

hey you just have to implement below lines after import modules:-嘿,你只需要在导入模块后实现以下几行:-

$iisAppPoolName = "my-test-app"
$iisAppPoolDotNetVersion = "v4.0"
$iisAppName = "my-test-app.test"
$directoryPath = "D:\SomeFolder"

Please let me know if you have any concern.如果您有任何疑问,请告诉我。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM