如何通过powershell下载公共谷歌驱动器文件并执行它们?

问题描述 投票:0回答:1

DNS Filter 是一个公开可用的工具,下面的脚本链接到所述 .msi 文件的实际下载。

#DNS Filter Variables
# $dnspath = "C:\Program Files\dnsfilter.msi";
# $dnsurl = "https://drive.google.com/uc?export=download&id=1NE0W0-zDEejLjxUSVEAK5ZPx2sDGeRIZ&confirm=t";

Set execution policy to unrestricted
Set-ExecutionPolicy Unrestricted -Scope CurrentUser

Download DNS Filter
Write-Output "Downloading current DNS Filter file"
Invoke-RestMethod -uri $dnsurl -OutFile $dnspath

这个 powershell 脚本曾经工作得很好,特别是“&confirm=t”变量允许通过 powershell 下载文件,同时绕过通常出现的确认。我相信从 2023 年 11 月到现在(24 年 1 月 16 日)之间的某个时间,谷歌驱动器末端发生了一些变化,破坏了脚本,因此它不再正确下载文件。

不幸的是,这个脚本要求确认,而之前它没有要求确认

现在,当该脚本运行时,它会下载一个 html 文件。我已附上...

我不知道如何修改上述网址才能再次开始绕过谷歌驱动器确认。

不是自动下载文件(就像 2024 年之前那样),这是在其位置下载的 html 文件:

<!DOCTYPE html><html><head><title>Google Drive - Virus scan warning</title><meta http-equiv="content-type" content="text/html; charset=utf-8"/><style nonce="bsh8CEl2DcDV3mgd_h4mXA">.goog-link-button{position:relative;color:#15c;text-decoration:underline;cursor:pointer}.goog-link-button-disabled{color:#ccc;text-decoration:none;cursor:default}body{color:#222;font:normal 13px/1.4 arial,sans-serif;margin:0}.grecaptcha-badge{visibility:hidden}.uc-main{padding-top:50px;text-align:center}#uc-dl-icon{display:inline-block;margin-top:16px;padding-right:1em;vertical-align:top}#uc-text{display:inline-block;max-width:68ex;text-align:left}.uc-error-caption,.uc-warning-caption{color:#222;font-size:16px}#uc-download-link{text-decoration:none}.uc-name-size a{color:#15c;text-decoration:none}.uc-name-size a:visited{color:#61c;text-decoration:none}.uc-name-size a:active{color:#d14836;text-decoration:none}.uc-footer{color:#777;font-size:11px;padding-bottom:5ex;padding-top:5ex;text-align:center}.uc-footer a{color:#15c}.uc-footer a:visited{color:#61c}.uc-footer a:active{color:#d14836}.uc-footer-divider{color:#ccc;width:100%}.goog-inline-block{position:relative;display:-moz-inline-box;display:inline-block}* html .goog-inline-block{display:inline}*:first-child+html .goog-inline-block{display:inline}sentinel{}</style><link rel="icon" href="//ssl.gstatic.com/docs/doclist/images/drive_2022q3_32dp.png"/></head><body><div class="uc-main"><div id="uc-dl-icon" class="image-container"><div class="drive-sprite-aux-download-file"></div></div><div id="uc-text"><p class="uc-warning-caption">Google Drive can't scan this file for viruses.</p><p class="uc-warning-subcaption">This file is executable and may harm your computer. <p class="uc-warning-subcaption"><span class="uc-name-size"><a href="/open?id=1NE0W0-zDEejLjxUSVEAK5ZPx2sDGeRIZ">DNS_Agent_Setup.msi</a> (3.8M)</span></p></p><form id="download-form" action="https://drive.usercontent.google.com/download" method="get"><input type="submit" id="uc-download-link" class="goog-inline-block jfk-button jfk-button-action" value="Download anyway"/><input type="hidden" name="id" value="1NE0W0-zDEejLjxUSVEAK5ZPx2sDGeRIZ"><input type="hidden" name="export" value="download"><input type="hidden" name="confirm" value="t"><input type="hidden" name="uuid" value="fbc7bc79-057c-4f5d-9882-73dc451e6f9c"></form></div></div><div class="uc-footer"><hr class="uc-footer-divider"></div></body></html>
powershell scripting google-drive-api
1个回答
0
投票

我看到两种解决方案:

  • 您可以压缩文件或类似的方式将其更改为不可执行的格式。
    Expand-Archive
    可以应付。
  • 您可以使用
    GoogleDrive
    模块
    下载文件而不会出现警告
    $credential = Import-Clixml -Path "Path\To\ServiceAccountKey.json"
    Connect-GoogleDrive -Credential $credential Authenticate with a Google service account
    $file = Get-DriveFile -FileId "123456-zDEejLjxUSVEAK5ZPx2sDGeRIZ"
    Export-DriveFile -DriveFile $file -Path $dnspath
    
© www.soinside.com 2019 - 2024. All rights reserved.