获取PowerShell脚本的文字命令行

问题描述 投票:1回答:1

出于涉及权限提升的原因,我需要能够以与最初运行时完全相同的方式调用脚本。出于这个原因,我希望能够检索用于最初调用脚本的文字,完整,未处理的命令行。最理想的是,这将表现如下:

# DoIt.ps1
Get-CommandLine | Write-Output

PS> ./DoIt.ps1 -Something something abc 123
./DoIt.ps1 -Something something abc 123

C:\> PowerShell.exe ./DoIt.ps1 -Something something abc 123
./DoIt.ps1 -Something something abc 123

但我可以处理保持PowerShell.exe,显然它不必是一个单独的cmdlet。

powershell command-line
1个回答
1
投票

根据MathiasTheMadTechnician的建议,我发现$MyInvocation.Line正是我正在寻找的东西。不知道谷歌为什么没有帮助,但我找到了答案。

© www.soinside.com 2019 - 2024. All rights reserved.