我一直在尝试用powershell下载和执行文件。一切正常,Powershell从"Workupload.com“下载文件并将其放入我的/user文件夹中。这对图片非常有效,下载后我也可以打开它们。
但是,当我在.exe或.txt文件中尝试它时,它不起作用。以下是我的代码:
$WebClient = New-Object System.Net.WebClient
$url = 'link to my .exe on workupload'
$dst = 'FireFox-Installer.exe' #Not adding a Path just puts the File in the User Folder
$WebClient.DownloadFile($url, $dst)
Start-Process $dst 'FireFox-Installer.exe'现在,当我尝试打开该文件时,我得到一个错误,即文件已损坏且不可读。我想知道我该怎么解决这个问题..是Windows-Defender阻止了它吗?我的代码是错误的吗?或者是文件托管器导致了错误?
以下是我的错误代码:
Start-Process : This command cannot be run due to the error: The file or directory is corrupted and unreadable.
At line:1 char:1
+ Start-Process $dst 'FireFox-Installer.exe'
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [Start-Process], InvalidOperationException
+ FullyQualifiedErrorId : InvalidOperationException,Microsoft.PowerShell.Commands.StartProcessCommand非常感谢大家的帮助,因为我是Powershell的新手,谢谢大家!:)
发布于 2020-08-13 22:48:28
好的,我试了一下,结果和预期的一样:
$WebClient = New-Object System.Net.WebClient
$url = 'https://download-installer.cdn.mozilla.net/pub/firefox/releases/79.0/win32/en-US/Firefox%20Installer.exe'
$dst = 'C:\Temp'
$WebClient.DownloadFile($url, (Join-Path $dst 'FireFox-Installer.exe'))
Start-Process (Join-Path $dst 'FireFox-Installer.exe')我刚刚为DownloadFile的destination参数添加了另一个Join-Path,如果它仍然不起作用,我建议您检查您的链接并测试您的Firefox-Installer.exe文件。
发布于 2020-10-20 02:49:53
如果您将目标根文件夹(例如\myserver\myshare)添加到IE中的受信任站点,然后关闭并重新启动PS会话,原始$dst是否可以工作?
https://stackoverflow.com/questions/63394008
复制相似问题