来自重定向网址的Powershell下载文件 - TeamViewer& Intune的

时间:2018-01-11 20:58:47

标签: powershell intune teamviewer

提前感谢任何有关此事的人。

我目前正在尝试通过Intune部署TeamViewer,它只支持MSI文件进行部署。但是,TeamViewer有一个称为帐户分配的功能,它以可执行文件的形式出现。由于Intune不允许您部署exe文件,如果我错了,请纠正我。我已经导致使用PowerShell脚本,它将下载必要的文件,然后安装。

我的目标是将文件存储在云中,如onedrive或Dropbox。问题在于公共链接并不直接指向文件作为其重定向。

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

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

如果两个链接都以文件扩展名(.exe)结尾,那么就没问题了。但我想使用Teamviewer链接(get.teamviewer.com/myhost重定向https://download.teamviewer.com/u/id12345/TeamViewer.exe,希望这可以帮助更多人。而不是拥有云存储帐户。

https://download.teamviewer.com/u/id12345/TeamViewer.exe也不是永久链接,它有一个到期时间。

我尝试的事情:

$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 

这些例子都不起作用我尝试了网上的点点滴滴的其他组合,但没有去。

1 个答案:

答案 0 :(得分:1)

您可以对所有示例使用以下URI:

  

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

您可以通过以下方式在Chrome中获取此下载URI:

  1. 下载TeamViewer
  2. 打开下载历史记录
  3. Right click the entry for the TeamViewer download and copy the download URI.
  4. 编辑:

    您可以使用以下命令解析实际链接的下载站点:

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

    现在您可以使用' $ downloadLink'用任何脚本下载可执行文件的变量。如果TeamViewer的下载页面发生更改,则可能需要更改此设置。

    只需搜索“再试一次”的ID即可。下载页面上的按钮。然后,您可以编辑我的代码以获取适当的元素和属性。