Powershell 下载并执行文件(文件或目录已损坏且无法读取)

Powershell Downloading and Executing Files (File or Directory is corrupted and unreadable)

我一直在尝试使用 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 是否阻止了它?我的代码错了吗?或者是导致错误的 File-Hoster?

这是我的错误代码:

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 的新手,谢谢大家! :)

好的,所以我刚刚试了一下,它按预期工作了:

$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 的目标参数添加了另一个 Join-Path 如果它仍然不起作用,我建议您检查您的 link 并测试您的 Firefox-Installer.exe 文件。

如果您将目标根文件夹(例如 \\myserver\myshare)添加到 IE 中的受信任站点,然后关闭并重新启动您的 PS 会话,原始 $dst 是否有效?