![](/img/trans.png)
[英]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.