因此,我试图写一个相当简单的,我认为每个4。这将在目录中查找,列出一组页面,然后取其名称,将其添加到IIS的错误页脚本中。会成功吗?!不.我从IIS那里得到了不一致的错误。有人有这个问题吗?有人看到我做错什么了吗.
目录列表是“
400.htm
401-1.htm
401-2.htm
401-3.htm
401-4.htm
401-5.htm
403-1.htm
403-10.htm
403-11.htm
403-12.htm
403-13.htm
403-14.htm
403-15.htm
403-16.htm
403-17.htm
403-2.htm
403-3.htm
403-4.htm
403-5.htm
403-6.htm
403-7.htm
403-8.htm
403-9.htm
403.htm
404-1.htm
404.htm
405.htm
406.htm
407.htm
410.htm
412.htm
414.htm
500-12.htm
500-13.htm
500-15.htm
500.htm
501.htm
502.htm
htmla.htm我的代码如下:
$files = dir D:\iis\errorpages
Foreach ($file in $files)
{
$file = $file -replace "[^0-9]"
Add-WebConfigurationProperty -pspath 'MACHINE/WEBROOT/APPHOST/Website' -filter "system.webServer/httpErrors" -name "." -value @{statusCode=$file;prefixLanguageFilePath='D:\iis\errorpages';path="$file"}
} 发布于 2017-10-25 20:58:48
在foreach的每个循环中,$file都包含一个具有某些属性的对象。使用regex行$file = $file -replace "[^0-9]",我假设您希望修改文件名。如果我的假设是正确的,那么您应该使用:
$fileName = $file.name -replace "[^0-9]"
这也可能是错误的:
-value @{statusCode=$file;prefixLanguageFilePath='D:\iis\errorpages';path="$file"
如果您想要路径和文件名,请使用属性fullname
如果您想要它所在的目录,则需要将属性fullname与字符串操作结合起来。像这样的$file.FullName.Substring(0, $file.FullName.LastIndexOf("\"))
https://stackoverflow.com/questions/46773234
复制相似问题