如何让 Write-Host 输出 $true

Dan*_*nce 5 powershell

我正在编写一个write-host用于输出另一个 powershell 脚本的 powershell 脚本。如何写出值为 $true(或 $false)的布尔参数,包括美元符号:

param
(
    [switch] $myParam = $true
)

Write-Host My Param is $myParam
Run Code Online (Sandbox Code Playgroud)

我需要这个来准确输出

My Param is $True
Run Code Online (Sandbox Code Playgroud)

但它输出

My Param is True
Run Code Online (Sandbox Code Playgroud)

Lee*_*Lee 6

您可以使用 ` 转义 $:

Write-Host My Param is `$$myParam
Run Code Online (Sandbox Code Playgroud)