[英]Powershell : How to create IIS 6 Virtual Directory/Web application under a Subfolder
[英]How to run the powershell code against each subfolder that is in the IIS root directory?
我想針對IIS根目錄中的每個子文件夾運行下面的powershell代碼。 對於每個子文件夾內容(僅包含該子文件夾中的文件),輸出應該是單獨的.htm文件。 如果您需要我澄清我的問題,請問。
$basedir = 'c:\inetpub\wwwroot'
$exp = [regex]::Escape($basedir)
$server = 'http://172.16.246.76'
function Create-HtmlList($fldr) {
Get-ChildItem $fldr -Force |
select ...
...
} | Set-Content "$fldr.htm"
}
# list files in $basedir:
Create-HtmlList $basedir
# list files in all subfolders of $basedir:
Get-ChildItem $basedir -Recurse -Force |
? { $_.PSIsContainer } |
% {
Create-HtmlList $_.FullName
}
您需要將文件夾遍歷(遞歸)與文件處理(非遞歸)分開,例如:
$basedir = 'c:\inetpub\wwwroot'
$exp = [regex]::Escape($basedir)
$server = 'http://172.16.x.x'
function Create-HtmlList($fldr) {
Get-ChildItem $fldr -Force |
? { -not $_.PSIsContainer } |
select ...
...
} | Set-Content "$fldr.htm"
}
# list files in $basedir:
Create-HtmlList $basedir
# list files in all subfolders of $basedir:
Get-ChildItem $basedir -Recurse -Force |
? { $_.PSIsContainer } |
% {
Create-HtmlList $_.FullName
}
輸出文件將放入相應的文件夾(以附加擴展名.htm
的文件夾命名)。 如果要為輸出文件使用不同的名稱或位置,則需要在Create-HtmlList
函數中調整Set-Content
行。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.