如何对IIS根目录中的每个子文件夹运行Powershell代码? [英] How to run the powershell code against each subfolder that is in the IIS root directory?

查看:107
本文介绍了如何对IIS根目录中的每个子文件夹运行Powershell代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想针对IIS根目录中的每个子文件夹运行下面的powershell代码。每个子文件夹内容的输出应为单独的.htm文件(仅包含该子文件夹中的文件)。

I would like to run the powershell code below, against each sub-folder that is in the IIS root directory. The output should be separate .htm file for each sub-folder contents (containing only the files in that sub-folder). If you need me to clarify my question, just ask.

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


推荐答案

您需要将文件夹遍历(递归)与文件处理(非递归)分开,例如像这样:

You need to separate folder-traversal (recursive) from file processing (non-recursive), e.g. like this:

$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 行。 c $ c>。

The output files will be put into the respective folder (named after the folder with the extension .htm appended). If you want a different name or location for the output files, you need to adjust the Set-Content line in the function Create-HtmlList.

这篇关于如何对IIS根目录中的每个子文件夹运行Powershell代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆