连接Powershell命令

时间:2018-06-22 05:20:23

标签: powershell invoke-command

我想在1行中运行以下命令:

$url = "https://githubxxxx/install.ps1"
$webClient = New-Object System.Net.WebClient 
$webClient.Proxy = [System.Net.GlobalProxySelection]::GetEmptyWebProxy()
$webClient.DownloadString($url) | Invoke-Expression

应与本文相似:
Run Powershell script from URL without temporary file

但是我不知道如何添加这一行:

$webClient.Proxy = [System.Net.GlobalProxySelection]::GetEmptyWebProxy()  

进入此命令:

iex ((New-Object System.Net.WebClient).DownloadString('https://githubxxxx/install.ps1'))  

我要实现的目标是在没有github代理的情况下运行它。

2 个答案:

答案 0 :(得分:2)

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

答案 1 :(得分:1)

您始终可以使用分号;将语句放在同一行中:

$webClient = New-Object System.Net.WebClient;$webClient.Proxy = [System.Net.GlobalProxySelection]::GetEmptyWebProxy()