![](/img/trans.png)
[英]How do I create a looped script with a wildcard value for the .jpg name, that downloads a set of images using a base url?
[英]How do I set the binding port number for a set of IIS websites with an increment value using PowerShell?
我有一個帶有許多網站的IIS后端服務器。 我只是使用powershell創建了這些站點。 我需要將每個網站的綁定端口設置為代理的唯一編號(從9200開始)。 我正在嘗試找到一種方法來編寫此腳本,但我很難找到一種解決方案。 目前,我在要設置綁定端口的文本文件中有一個網站列表。 現在,這就是我所擁有的:
Import-Module WebAdministration
$endpoints = Get-Content C:\scripts\endpoints.txt
foreach ($number in 9200..9310)
{
foreach ($site in $endpoints)
{
Set-WebBinding -Name '$site' -BindingInformation "*:80:" -PropertyName Port -Value $number
}
}
我有第一個foreach循環的原因是因為我總共有110個網站,所以從9200-9310獲得端口號。 我會以錯誤的方式處理嗎?
看來問題是您的兩個foreach
循環。 您在包含端口號的第二個foreach
循環中。 因此,您的第一個循環從$number = 9200
,然后將每個$site
設置為當時在$number
變量中保存的端口,然后退出該循環並遞增端口號,然后重新開始。
我想出了一些可以解決您問題的方法。
Import-Module WebAdministration
$endpoints = Get-Content C:\scripts\endpoints.txt
$ports = New-Object System.Collections.ArrayList
[int] $port = 9200
[int] $counter = 0
while($port -le 9310) {
$ports.Add($port)
$port++
}
foreach ($site in $endpoints)
{
Set-WebBinding -Name '$site' -BindingInformation "*:80:" -PropertyName Port -Value $ports[$counter]
$counter++
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.