\{CURL_EQUIVALENT_ON_WIN...">

Curl http: //url/script.ps1 | Is a "shell" possible?

I just want to reproduce the same behavior as on Linux systems

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

Is it possible?

Basically I want to execute a stream loaded from the server.

IE: step by step:

1) Learn how to execute threads in the shell. Execute the stream (which I already have on the file system)

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

but it does not work.

There is the -File option for executing the "File", and basically I want to, if possible, execute the stream.

2) Learn how to execute the stream that I download from the server and connect it to the powershell file.

+6
source share
2 answers

You can specify a powershell command parameter with a hyphen so that it reads its command from standard input. The following is an example:

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

An example of using the contents of a script file:

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

In the powershell help menu:

 powershell /? 

-command
Executes the specified commands (and any parameters) as if they were printed on the Windows PowerShell command prompt, and then will exit if NoExit is specified. Command value can be "-" string. or script.

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

Thanks to dugas, I will learn how to execute streams with powershell, and using this link http://blog.commandlinekungfu.com/2009/11/episode-70-tangled-web.html I understand how to get content as a stream from http with powershell.

So, the final twist | The PowerShell pipe is as follows:

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

Thanks to everyone who contributes to this question :-)

+7
source

Source: https://habr.com/ru/post/943459/


All Articles