Last active
March 9, 2017 09:35
-
-
Save johnybradshaw/1f4fa2a13508f52f3a769c200db7175c to your computer and use it in GitHub Desktop.
This will install a version of Dropbox on a Windows OS that has Powershell support
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Dropbox Powershell installer | |
#Version 3.2 | |
#Download and install the latest version of Dropbox for the purposes of Enterprise deployment | |
$source = 'C:\source' #Change this to a download directory of your choosing | |
$arguments = '/s' #Change /s to /NOLAUNCH to prevent client start | |
#Check to see if the user has the Administrator role on the machine, if not die | |
If (-NOT ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole(` | |
[Security.Principal.WindowsBuiltInRole] "Administrator")) | |
{ | |
Write-Warning "You do not have Administrator rights to run this script!`nPlease re-run this script as an Administrator!" | |
exit | |
} | |
Function Get-RedirectedUrl { | |
Param ( | |
[Parameter(Mandatory=$true)] | |
[String]$url | |
) | |
$request = [System.Net.HttpWebRequest]::Create($url) | |
$request.AllowAutoRedirect=$true | |
try{ | |
$response=$request.GetResponse() | |
#Write-Host $response.ResponseURI.AbsoluteUri | |
$url = $response.ResponseURI.AbsoluteUri | |
return $url | |
$response.Close() | |
} | |
catch{ | |
"ERROR: $_" | |
break | |
} | |
} | |
#Delete old installer files | |
Remove-Item($source + "\Dropbox%20*.exe") | |
$url = Get-RedirectedUrl("https://www.dropbox.com/download?full=1&os=win") #This is the current Dropbox offline installer URL | |
#Find the Dropbox client version number from the registry | |
$client_ver1 = Get-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\DropboxUpdate\Update\Clients\{CC46080E-4C33-4981-859A-BBA2F780F31E}\' | Select-Object -ExpandProperty pv | |
$client_ver2 = Get-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Dropbox\Client\' | Select-Object -ExpandProperty Version | |
#Check to see if both version numbers match the version in the URL | |
If (!($url -match $client_ver2 -And $url -match $client_ver1)){ | |
#Strip the URL to leave the file name | |
$fileName = Split-Path $url -Leaf | |
$destinationPath = $source + "\" + $fileName | |
$webClient = New-Object System.Net.WebClient | |
[int]$trials = 0 | |
do { | |
try { | |
$trials +=1 | |
Write-Output "Downloading Dropbox" | |
$webClient.DownloadFile($url,$destinationPath) | |
break | |
} catch [System.Net.WebException] { | |
write-host "Problem downloading $url `tTrial $trials ` | |
`n`tException: " $_.Exception.Message | |
exit | |
} | |
} | |
while ($trials -lt 3) | |
<# | |
$webClient = New-Object System.Net.WebClient | |
Write-Output "Downloading Dropbox" | |
$webClient.DownloadFile($url,$destinationPath) #> | |
Write-Output "Installing Dropbox" | |
Invoke-Expression -Command "$destinationPath $arguments" | |
} else { | |
Write-Host "Dropbox client already installed... exiting." | |
exit | |
} | |
<#MIT License | |
Copyright (c) 2017 John Bradshaw | |
Permission is hereby granted, free of charge, to any person obtaining a copy | |
of this software and associated documentation files (the "Software"), to deal | |
in the Software without restriction, including without limitation the rights | |
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
copies of the Software, and to permit persons to whom the Software is | |
furnished to do so, subject to the following conditions: | |
The above copyright notice and this permission notice shall be included in all | |
copies or substantial portions of the Software. | |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
SOFTWARE.#> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment