Advertisement
iron-from-sf

update_script_powerbi

Jun 17th, 2024 (edited)
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PowerShell 2.18 KB | Software | 0 0
  1. # Enable TLS 1.2
  2. [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
  3.  
  4. # Define variables
  5. $gatewayDownloadUrl = "https://go.microsoft.com/fwlink/?linkid=820931"
  6. $downloadPath = "C:\Temp\PowerBIGatewayInstaller.exe"
  7. $installPath = "C:\Program Files\On-premises data gateway\Microsoft.PowerBI.EnterpriseGateway.exe"
  8.  
  9. # Function to get the version of an executable file
  10. function Get-FileVersion {
  11.     param (
  12.         [string]$filePath
  13.     )
  14.  
  15.     # Extract the version from the file
  16.     $version = (Get-Command $filePath).FileVersionInfo.FileVersion
  17.     return $version
  18. }
  19.  
  20. # Get the installed version from the executable file
  21. $installedVersion = Get-FileVersion -filePath $installPath
  22.  
  23. # Create Temp directory if it does not exist
  24. if (-Not (Test-Path -Path "C:\Temp")) {
  25.     New-Item -Path "C:\Temp" -ItemType Directory
  26. }
  27.  
  28. # Download the latest Power BI Gateway installer
  29. try {
  30.     Invoke-WebRequest -Uri $gatewayDownloadUrl -OutFile $downloadPath -ErrorAction Stop
  31. } catch {
  32.     Write-Host "Download failed: $_"
  33.     exit 1
  34. }
  35.  
  36. # Get the version of the downloaded installer
  37. $latestVersion = Get-FileVersion -filePath $downloadPath
  38.  
  39. Write-Host "Installed Version: $installedVersion"
  40. Write-Host "Latest Version: $latestVersion"
  41.  
  42. # Compare versions
  43. if ($installedVersion -eq $latestVersion) {
  44.     Write-Host "The installed version is up to date. No update required."
  45.     Remove-Item -Path $downloadPath -Force
  46.     exit 0
  47. }
  48.  
  49. # Stop the existing Power BI Gateway service
  50. try {
  51.     Stop-Service -Name PBIEgwService -Force
  52. } catch {
  53.     Write-Host "Failed to stop PBIEgwService: $_"
  54.     exit 1
  55. }
  56.  
  57. # Install the new Power BI Gateway
  58. try {
  59.     Start-Process -FilePath $downloadPath -ArgumentList "/quiet" -Wait
  60. } catch {
  61.     Write-Host "Installation failed: $_"
  62.     exit 1
  63. }
  64.  
  65. # Start the Power BI Gateway service
  66. try {
  67.     Start-Service -Name PBIEgwService
  68. } catch {
  69.     Write-Host "Failed to start PBIEgwService: $_"
  70.     exit 1
  71. }
  72.  
  73. # Cleanup the downloaded installer
  74. try {
  75.     Remove-Item -Path $downloadPath -Force
  76. } catch {
  77.     Write-Host "Cleanup failed: $_"
  78.     exit 1
  79. }
  80.  
  81. Write-Host "Power BI Gateway has been updated successfully."
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement