powershell - 在 PowerShell 中脚本回显当前命令

标签 powershell

假设我正在运行一个带有多个输入参数的 PowerShell 脚本。命令看起来像:

psScript.ps1 -arg1 "arg1value" -arg2 "arg2value"

有没有办法将这个确切的命令存储在脚本中的变量中,以便我可以记录它?

具体来说,我想知道分配给变量 $currentCommand 的内容:
$currentCommand = <something>
Write-Host "currently running script " $currentCommand

这样 Write-Host 输出将是用于调用脚本的确切命令行。例如,如果脚本命令与上述相同,则输出将是:

currently running script psScript.ps1 -arg1 "arg1value" -arg2 "arg2value"

最佳答案

这可能适合您的需求:

Write-Host "currently running script " $myinvocation.Line

Reference

关于powershell - 在 PowerShell 中脚本回显当前命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14283535/

相关文章:

powershell - 如何将文件列表作为参数传递给 powershell 脚本

c# - 如何将 C# 控制台转换为 Powershell?

windows - 如何将 IIS AppPools 的应用程序放入数组?

powershell - 为什么 Export-CSV 会覆盖整个 CSV 内容而不是只覆盖指定的数据?

azure - PowerShell 任务未在 Azure Pipelines 中运行脚本?

powershell - Azure - 及时访问您不拥有的订阅中的虚拟机

java - 如何在服务器上通过 Java 运行 Powershell 命令

powershell - 将 cmdlet 的结果值存储在 Powershell 中的变量中

excel - 如何显示(或防止隐藏)从 PowerShell 创建的 Excel 工作表

powershell - 自动登录Azure powershell