我有一个csv文件,其中包含10个不同的网站configuration。
我已经创build了下面的脚本来自动创build它们。 当我testing脚本,它运行成功,但我想知道这是否是自动化网站创build的最佳devise。 我使用循环和if / else语句是否正确?
我希望有人可以审查,让我知道,如果这个脚本看起来不错。
我也想知道是否有办法在不同的虚拟目录上设置不同的权限? 例如,如果我有一个用于上传和下载的文件夹,有没有办法通过PowerShell脚本来为该虚拟目录设置读/写权限?
谢谢!
#populate array object with contents from webservers.csv file $webObjects = Import-Csv c:\\iis\webservers.csv ForEach ($obj in $webObjects) { $name = $obj.WebSiteName $path = $obj.Path $vPath = $obj.VirtualDirectory $appPool = $obj.AppPoolName $appPoolId = $obj.appPoolIdentity $dotNetVersion = $obj.DotNetVersion $port = $obj.Port #new website path if ( ! (Test-Path $path)) { New-Item -type directory -path $path } else { Write-Host "The path already exists." -BackgroundColor Blue -ForegroundColor White } #new website virtual path if ( ! (Test-Path $vPath)) { New-Item -type directory -path $vPath } else { Write-Host "The path already exists." -BackgroundColor Blue -ForegroundColor White } #New application pool if ( ! (Test-Path "iis:\appPools\$appPool")) { New-WebAppPool $appPool } else { Write-Host "This application pool already exists." -BackgroundColor Blue -ForegroundColor White } if (Test-Path "iis:\appPools\$appPool") { Set-ItemProperty IIS:\AppPools\$appPool managedRuntimeVersion $dotNetVersion } else { Write-Host "This application pool does not exist." -BackgroundColor Blue -ForegroundColor White } #New website if ( ! (Test-Path "iis:\Sites\$name")) { New-WebSite -Name $name -PhysicalPath $path -ApplicationPool $appPool -Port $port } else { Write-Host "A website with the name $name at $path already exists." -BackgroundColor Blue -ForegroundColor White } #New virtual directory if ( ! (Test-Path $vPath)) { New-WebVirtualDirectory -Site $name -Name $name -PhysicalPath -$vPath } else { Write-Host "A virtual directory with the name $name at $vPath already exists." -BackgroundColor Blue -ForegroundColor White }
}