首页 > 解决方案 > 将参数传递给 powershell 调用表达式命令

问题描述

我的问题与此类似:
How to pass arguments to an Invoke-Expression, in Powershell?

我有以下命令:

powershell iex ((New-Object Net.WebClient -Property @{Proxy = [Net.GlobalProxySelection]::GetEmptyWebProxy()}).DownloadString('https://github/test.ps1'))

如果可能的话,我想以某种方式将以下参数传递给这个命令,所以只需扩展我的命令。

"${node.site}" "${node.zone}"

如果一根线不可能,也可以放两根线。

标签: powershellgithubinvoke-commandwindows-scriptingrundeck

解决方案


您可以通过帮助搜索PowerShell.exe--> 'PowerShell.exe /?' 从 PowerShell/cmd 控制台。

下面是您要求的一个可能示例。

PowerShell -Command " & {param(`$r) Write-Output `$r }" 'sometext'

也许对你

powershell -command " & {param(`$Url) iex ((New-Object Net.WebClient -Property @{Proxy = [Net.GlobalProxySelection]::GetEmptyWebProxy()}).DownloadString(`$Url))}" 'https://github/test.ps1'

推荐阅读