我编写了自己的Powershell日志记录函数Log,stream其中包含参数(写入消息的流)和message(要写入的消息).
我的想法是我可以将输出写入控制台和日志文件.我在函数中做的基本上是确定发布消息的流(使用switch语句),然后将消息写入流和日志文件:
switch ($stream) {
Verbose {
Write-Output "$logDate [VERBOSE] $message" | Out-File -FilePath $sgLogFileName -Append
Write-Verbose $message
break
}
}
Run Code Online (Sandbox Code Playgroud)
现在的问题是,是否有可能检查是否给出了-Verbose参数?
目标是仅在给出-Verbose时将消息写入日志文件.
我已经查看了以下帮助文档,但没有找到任何帮助:
- help about_Parameters
- help about_commonparameters
此外,-WhatIf参数不适用于Write-Verbose.
非常感谢你的回答!
powershell ×1