首页 > 解决方案 > 为什么 -whatif 参数不传递给管道

问题描述

-Whatif在 Powershell 脚本中使用公共参数,例如:

Remove-Item -Path "$now\$basename" -Recurse -Whatif -Force |
    Write-Entry -Line $(get-linenumber) -level 'Info' | 
    Create-Log -title "$title.log" -display

即使我可以清楚地看到屏幕上的文本,日志文件也是空白的。我想将-Whatif字符串传递给文本文件。我知道这与重定向有关,但据我所知。

标签: powershelllogging

解决方案


处理的输出-Whatif绕过标准流进行输出,直接进入控制台。这个关于从 C#访问输出的 TechNet 问题-WhatIf解释了。


推荐阅读