【发布时间】:2021-05-27 19:18:40
【问题描述】:
为了呈现问题,我将这个简单的脚本保存为 PowerShell 模块 (test.psm1)
Write-Verbose 'Verbose message'
在现实生活中,它包括导入附加功能的命令,但目前无关紧要。
如果我运行 Import-Module .\test.psm1 -Verbose -Force 我只会得到
VERBOSE: Loading module from path 'C:\tmp\test.psm1'.
我的Write-Verbose 被忽略了????
我尝试添加cmdletbinging,但也没有用。
[cmdletbinding()]
param()
Write-Verbose 'Verbose message'
知道如何在导入 PowerShell 模块时提供详细输出吗?
附:我不想总是显示详细信息,但前提是指定了-Verbose。以下是我对这两种不同情况的预期输出:
PS C:\> Import-Module .\test.psm1 -Verbose -Force # with verbose output
VERBOSE: Loading module from path 'C:\tmp\test.psm1'.
VERBOSE: Verbose message
PS C:\> Import-Module .\test.psm1 -Force # without verbose output
PS C:\>
【问题讨论】:
-
我知道问题stackoverflow.com/questions/16406682,但我不想显示来自命令行开关的详细消息。我想在导入模块时显示详细信息。
-
您是否尝试过在
Write-Verbose命令中也使用-Verbose? -
@MarcoLuzzara,感谢您的提示。至少在我的测试中,它总是显示详细信息,无论我在导入时是否指定 -Verbose。我扩展了我的问题以澄清这一点。我也尝试过使用 $PSBoundParameters,但也没有用。
标签: powershell module verbose