简体   繁体   English

Powershell从重定向URL下载文件-TeamViewer和Intune

[英]Powershell download file from redirecting url - TeamViewer & Intune

Thank you in advance for anyone taking a look into this. 预先感谢任何关注此内容的人。

I'm currently trying to deploy TeamViewer via Intune that only support MSI files for deployment. 我目前正在尝试通过Intune部署仅支持MSI文件进行部署的TeamViewer。 However, TeamViewer has a feature called account assignment which it comes in form of an executable. 但是,TeamViewer具有称为帐户分配的功能,该功能以可执行文件的形式出现。 Since Intune doesn't allow you deploy exe files, please correct me if I'm wrong. 由于Intune不允许您部署exe文件,因此如果我错了,请更正我。 I have resulted in using a PowerShell script that will download the necessary files and then install. 我导致使用PowerShell脚本,该脚本将下载必要的文件然后进行安装。

My goal is to have the files stored in the cloud like onedrive or Dropbox. 我的目标是将文件存储在像onedrive或Dropbox这样的云中。 The problem there is the public link doesn't point to the file directly as its a redirect. 公用链接的问题不是直接指向文件,而是重定向。

For example https://www.dropbox.com/x/xyzd/TeamViewer_Assignment.exe?dl=0 --> https://www.dropbox.com/x/xyzd/TeamViewer_Assignment.exe 例如https://www.dropbox.com/x/xyzd/TeamViewer_Assignment.exe?dl=0- > https://www.dropbox.com/x/xyzd/TeamViewer_Assignment.exe

or 要么

https://1drv.ms/u/s!Avjfi0upMYg9haNVTMpdoPGdstex --> https://1drv.ms/u/s/teamviewer.exe https://1drv.ms/u/s!Avjfi0upMYg9haNVTMpdoPGdstex- > https://1drv.ms/u/s/teamviewer.exe

if both links were to end with the file extension (.exe), then it would be no problem. 如果两个链接都以文件扩展名(.exe)结尾,那将没有问题。 But I would like to use Teamviewer links (get.teamviewer.com/myhost redirects https://download.teamviewer.com/u/id12345/TeamViewer.exe hoping this will help a lot more people. As opposed to having a cloud storage account. 但是我想使用Teamviewer链接(get.teamviewer.com/myhost重定向https://download.teamviewer.com/u/id12345/TeamViewer.exe希望这对更多人有帮助。相对于拥有云存储帐户。

https://download.teamviewer.com/u/id12345/TeamViewer.exe is not a permanent link either, and it has an expiration time. https://download.teamviewer.com/u/id12345/TeamViewer.exe也不是永久链接,并且具有到期时间。

Things I've tried: 我尝试过的事情:

$url = "https://get.teamviewer.com/mycustomhost"
$output = "$PSScriptRoot\myhost.exe"
$start_time = Get-Date

Invoke-WebRequest -Uri $url -OutFile $output
Write-Output "Time taken: $((Get-Date).Subtract($start_time).Seconds) 
second(s)"

$url = "http://get.teamviewer.com/myhost"
$output = "$PSScriptRoot\myhost.exe"
$start_time = Get-Date

$wc = New-Object System.Net.WebClient
$wc.DownloadFile($url, $output)
#OR
(New-Object System.Net.WebClient).DownloadFile($url, $output)

Write-Output "Time taken: $((Get-Date).Subtract($start_time).Seconds) 
second(s)"

$rep=Invoke-WebRequest 
http://www.get.teamviewer.com/myhost -MaximumRedirection 
0 
$rep.Links | where {$_.innerText -eq "click here"} |select -expand href 

None of those examples worked I tried other combination from bits and pieces over the net but no go. 这些示例都没有奏效,我尝试了网络上一点一点的其他组合,但没有成功。

You can use the following URI for all of your examples: 您可以对所有示例使用以下URI:

https://customdesign.teamviewer.com/download/version_12x/myhost/TeamViewerQS.exe https://customdesign.teamviewer.com/download/version_12x/myhost/TeamViewerQS.exe

You can get this URI for your download in Chrome in the following way: 您可以通过以下方式在Chrome中下载该URI:

  1. Download TeamViewer 下载TeamViewer
  2. Open the Download History 打开下载历史记录
  3. Right click the entry for the TeamViewer download and copy the download URI. 右键单击TeamViewer下载条目,然后复制下载URI。

Edit: 编辑:

You can parse the download site for the real link with the following command: 您可以使用以下命令来解析下载站点的真实链接:

$downloadPage = Invoke-WebRequest -Uri https://get.teamviewer.com/myhost
$downloadLink = $request.ParsedHtml.getElementById('MasterBodyContent_btnRetry').href

Now you can use the '$downloadLink' variable to download the executable with any of your scripts. 现在,您可以使用'$ downloadLink'变量来使用任何脚本下载可执行文件。 You may have to change this if the download page for TeamViewer changes. 如果TeamViewer的下载页面发生更改,则可能必须更改此设置。

Just search for the id of the 'Try again' button on the download page. 只需在下载页面上搜索“重试”按钮的ID。 Then you can edit my code to get the appropriate element and attribute. 然后,您可以编辑我的代码以获取适当的元素和属性。

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

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