2013-04-23 114 views
6

我只是想複製我在Linux系統上做同樣的行爲curl http://url/script.ps1 | PowerShell可能嗎?

c:\> \{CURL_EQUIVALENT_ON_WINDOWS} - http://url/script | powershell 

這可能嗎?

基本上我想執行從服務器下載的流。

IE:在以下步驟:

1)瞭解如何在執行的powershell流。 執行流(即我已經有文件系統)

c:\> type script.ps1 | powershell -command - 

但這不起作用。

有一個選項 - 文件執行「文件」,基本上我想如果可能的執行流。

2)瞭解如何執行流我從服務器和管道將其下載到一個PowerShell。

+0

嗯,嘗試一下? :-) – akluth 2013-04-23 16:54:03

+0

你在期待什麼'| powershell'做什麼? – 2013-04-23 17:00:19

+0

只是爲了運行流 – p4tux 2013-04-23 17:45:02

回答

3

您可以使用連字符指定powershell的命令參數,使其從標準輸入中讀取其命令。下面是一個例子:

Get-Content .\test.ps1 | powershell -command - 

從PowerShell幫助菜單:

powershell /? 

-Command
執行指定

"Write-Host This is a test" | powershell -command - 

的腳本文件的使用示例內容命令(以及任何參數),就好像它們是在Windows P上鍵入的 owerShell命令提示符,然後退出,除非 指定NoExit。 Command的值可以是「 - 」,一個字符串。或一個 腳本塊。

If the value of Command is "-", the command text is read from standard 
input. 
+0

嗯我試着用腳本:type script.ps1 | PowerShell的-command - 和它不工作:-(療法是-file選項,但是這將是毫無價值的,基本上我想執行流 – p4tux 2013-04-23 17:50:35

+1

我使用的腳本文件的內容示例更新您需要管的內容該文件,而不僅僅是指定文件這將管內的文件作爲字符串的內容,就像下載文件,捲曲會 – dugas 2013-04-23 17:59:11

7

由於杜加斯我學會了如何使用PowerShell執行流,以及與此鏈接http://blog.commandlinekungfu.com/2009/11/episode-70-tangled-web.html我明白如何讓內容從http使用PowerShell流。

所以最終捲曲| PowerShell的管道是這樣的:

PS C:\>(New-Object System.Net.WebClient).DownloadString("http://url/script.ps1") | powershell -command - 

非常感謝大家,有助於這個問題:-)

+3

您也可以使用'調用-Expression':'(新物體System.Net .WebClient).DownloadString(「http://url/script.ps1」)| iex'。[PsGet](http://psget.net/)就是這樣做的。 – 2013-04-23 18:27:21