2014-12-30 45 views
-6

有人可以帮助我从power shell创建网站。下面写的脚本不起作用。在IIS中创建网站的Powershell脚本

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 
+16

你没有写这个剧本,你直接从以下站点复制它:[剧本原作者] (http://geekswithblogs.net/QuandaryPhase/archive/2013/02/24/create-iis-app-pool-and-site-with-windows-powershell.aspx)并没有使用它们的变量声明。 – Sage

回答

2

嘿,你只需要导入后的模块来实现以下线路: -

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

请让我知道如果您有任何顾虑。

9

对我来说,新建项目没有工作,我不得不用新的专用网站是这样的:

$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"}