简体   繁体   English

Powershell 2文件执行脚本

[英]Powershell 2 Files Execution Script

I'm tryng to run the following ps1 script我正在尝试运行以下 ps1 脚本

 PowerShell (New-Object System.Net.WebClient).DownloadFile('https://server/file1.exe','file1.exe');Start-Process 'file1.exe' PowerShell (New-Object System.Net.WebClient).DownloadFile('https://server/file2.exe','file2.exe');Start-Process 'file2.exe'

But I'm only being able to download the file1.exe without it to run但我只能下载 file1.exe 没有它运行

How can I do download and execute file1.exe and after that file2.exe如何下载并执行 file1.exe 以及之后的 file2.exe

Thank you谢谢

Try giving the Full path and filename for the downloaded files.尝试为下载的文件提供完整路径和文件名。

$file1 = 'D:\Test\file1.exe'
$file2 = 'D:\Test\file2.exe'

$webClient = New-Object System.Net.WebClient
$webClient.DownloadFile('https://server/file1.exe',$file1)
$webClient.DownloadFile('https://server/file2.exe',$file2)
$webClient.Dispose()

Then to run the executables one after the other:然后依次运行可执行文件:

$process = Start-Process $file1 -PassThru 
$process.WaitForExit()

$process = Start-Process $file2 -PassThru 
$process.WaitForExit()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM