【发布时间】:2018-10-16 05:22:55
【问题描述】:
我用 Plaster 制作了一个 powershell 模块。我有写详细的功能。那些工作很棒。例如:
function Get-Foo {
[CmdletBinding()]
[OutputType([string])]
param()
Write-Verbose "Writing foo"
"foo"
}
Get-Foo -Verbose
VERBOSE: Writing foo
foo
但是,当我执行 Import-Module -Verbose -Force 时,我有一些带有 Write-Verbose 的启动代码不会打印到屏幕上
[string] $TenantId = $null
try {
$tenantInfo = Get-AzureADTenantDetail
$TenantId = $tenantInfo.ObjectId
Write-Verbose "Found existing connection AzureAd connection to tenant $($TenantId) ($($tenantInfo.DisplayName))"
} catch [Microsoft.Open.Azure.AD.CommonLibrary.AadNeedAuthenticationException] {
Write-Verbose "No Existing Azure Ad connection found"
}
>Import-Module .\Foo.psd1 -Verbose -Force
VERBOSE: Loading module from path 'C:\Users\zippy\Source\Repos\psfoo\Foo.psd1'.
VERBOSE: Removing the imported "Get-AccessToken" function.
VERBOSE: Loading 'Assembly' from path 'C:\Users\zippy\Source\Repos\psfoo\Microsoft.Open.Azure.AD.CommonLibrary'.
VERBOSE: Loading 'Assembly' from path 'C:\Users\zippy\Source\Repos\psfoo\Microsoft.Open.Azure.AD.CommonLibrary'.
VERBOSE: Loading module from path 'C:\Users\zippy\Source\Repos\psfoo\Foo.psm1'.
VERBOSE: Importing function 'Get-AccessToken'.
我什至尝试将[CmdletBinding()]param() 添加到 psm1 的顶部,这不会破坏我的脚本,但也不会使详细消息可见。
【问题讨论】:
标签: powershell