Install-Compass.ps1 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #Requires -Version 3.0
  2. <#
  3. .SYNOPSIS
  4. Download and install latest version of MongoDB Compass.
  5. .DESCRIPTION
  6. A longer description.
  7. .INPUTS
  8. Description of objects that can be piped to the script
  9. .OUTPUTS
  10. Description of objects that are output by the script
  11. .EXAMPLE
  12. Example of how to run the script
  13. .LINK
  14. Links to further documentation
  15. .NOTES
  16. Detail on what the script does, if this is needed
  17. #>
  18. param()
  19. $ErrorActionPreference = 'Stop'
  20. $CompassUrl = 'https://compass.mongodb.com/api/v2/download/latest/compass/stable/windows'
  21. $TemporaryDir = [System.IO.Path]::GetTempPath()
  22. $CompassExe = "$TemporaryDir" + "compass-install.exe"
  23. Remove-Item $CompassExe -ErrorAction:Ignore
  24. try {
  25. Write-Output "Downloading Compass from $CompassUrl"
  26. # Default PowerShell SecurityProtocol does not support Tls1.2 (required by domain)
  27. if ([Net.ServicePointManager]::SecurityProtocol.ToString() -NotMatch "Tls12") {
  28. [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
  29. }
  30. Invoke-WebRequest -Uri $CompassUrl -OutFile $CompassExe
  31. Write-Output "Installing Compass"
  32. & $CompassExe
  33. Write-Output "Successfully installed Compass"
  34. } catch {
  35. # Fail silently. With the way that we've hooked into the MSI
  36. # currently we're not able to do any meaningful error reporting
  37. # and not crash the installer.
  38. Write-Output "Error installing Compass."
  39. }
  40. # Remove the binary we downloaded
  41. Remove-Item $CompassExe -ErrorAction:Ignore