Skip to content

Invoke-Command does not apply VerbosePreference to ScriptBlock #4040

@bergmeister

Description

@bergmeister

Steps to reproduce

PowerShell 6Beta2 still has the same gotcha as Windows PowerShell that one needs to manually pass and set the VerbosePreference into scriptblocks, even when using advanced functions. It would be nice if the VerbosePreference of the Invoke-Command Cmdlet would be set automatically in the executed scriptblock.

Invoke-Command -ScriptBlock {Write-Verbose "Hello World"} -Verbose

Invoke-Command -ScriptBlock {[CmdletBinding()]Param() Write-Verbose "Hello World"} -Verbose

Expected behavior

I would expect in both cases that the VerbosePreference gets applied automatically
VERBOSE: Hello World

Actual behavior

No verbose output.
One has to pass and set it manually to get it working:
Invoke-Command -ScriptBlock {[CmdletBinding()]Param($VerbosePreference) Write-Verbose "Hello World"} -Verbose -ArgumentList ('Continue')

Environment data

Name                           Value
----                           -----
PSVersion                      6.0.0-beta
PSEdition                      Core
BuildVersion                   3.0.0.0
CLRVersion
GitCommitId                    v6.0.0-beta.2
OS                             Microsoft Windows 10.0.15063
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-Discussionthe issue may not have a clear classification yet. The issue may generate an RFC or may be reclassifResolution-No ActivityIssue has had no activity for 6 months or moreWG-Languageparser, language semantics

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions