簡體   English   中英

Powershell從重定向URL下載文件-TeamViewer和Intune

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

預先感謝任何關注此內容的人。

我目前正在嘗試通過Intune部署僅支持MSI文件進行部署的TeamViewer。 但是,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 

這些示例都沒有奏效,我嘗試了網絡上一點一點的其他組合,但沒有成功。

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

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

您可以通過以下方式在Chrome中下載該URI:

  1. 下載TeamViewer
  2. 打開下載歷史記錄
  3. 右鍵單擊TeamViewer下載條目,然后復制下載URI。

編輯:

您可以使用以下命令來解析下載站點的真實鏈接:

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

現在,您可以使用'$ downloadLink'變量來使用任何腳本下載可執行文件。 如果TeamViewer的下載頁面發生更改,則可能必須更改此設置。

只需在下載頁面上搜索“重試”按鈕的ID。 然后,您可以編輯我的代碼以獲取適當的元素和屬性。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM