我想通过设置标志和在 PowerShell 脚本中输出变量和值查看整个脚本中的数据.
I would like to output variables and values out in a PowerShell script by setting up flags and seeing the data matriculate throughout the script.
我该怎么做?
例如,与以下 PHP 代码等效的 PowerShell 是什么?
For example, what would be the PowerShell equivalent to the following PHP code?
echo "filesizecounter: " . $filesizecounter 推荐答案有以下几种方式:
Write-Host:直接写入控制台,不包含在函数/cmdlet 输出中.允许设置前景色和背景色.
Write-Host: Write directly to the console, not included in function/cmdlet output. Allows foreground and background colour to be set.
Write-Debug:直接写入控制台,如果 $DebugPreference 设置为继续或停止.
Write-Debug: Write directly to the console, if $DebugPreference set to Continue or Stop.
Write-Verbose:直接写入控制台,如果 $VerbosePreference 设置为继续或停止.
Write-Verbose: Write directly to the console, if $VerbosePreference set to Continue or Stop.
后者用于额外的可选信息,Write-Debug 用于调试(所以似乎适合这种情况).
The latter is intended for extra optional information, Write-Debug for debugging (so would seem to fit in this case).
附加:在 PSH2(至少)脚本中使用 cmdlet 绑定会自动获取 -Verbose 和 -Debug 开关参数,本地启用Write-Verbose 和 Write-Debug(即覆盖首选项变量),就像编译的 cmdlet 和提供程序一样.
Additional: In PSH2 (at least) scripts using cmdlet binding will automatically get the -Verbose and -Debug switch parameters, locally enabling Write-Verbose and Write-Debug (i.e. overriding the preference variables) as compiled cmdlets and providers do.
更多推荐
PowerShell 中的 Echo 等效脚本测试
发布评论