Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Enable TLS 1.2
- [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
- # Define variables
- $gatewayDownloadUrl = "https://go.microsoft.com/fwlink/?linkid=820931"
- $downloadPath = "C:\Temp\PowerBIGatewayInstaller.exe"
- $installPath = "C:\Program Files\On-premises data gateway\Microsoft.PowerBI.EnterpriseGateway.exe"
- # Function to get the version of an executable file
- function Get-FileVersion {
- param (
- [string]$filePath
- )
- # Extract the version from the file
- $version = (Get-Command $filePath).FileVersionInfo.FileVersion
- return $version
- }
- # Get the installed version from the executable file
- $installedVersion = Get-FileVersion -filePath $installPath
- # Create Temp directory if it does not exist
- if (-Not (Test-Path -Path "C:\Temp")) {
- New-Item -Path "C:\Temp" -ItemType Directory
- }
- # Download the latest Power BI Gateway installer
- try {
- Invoke-WebRequest -Uri $gatewayDownloadUrl -OutFile $downloadPath -ErrorAction Stop
- } catch {
- Write-Host "Download failed: $_"
- exit 1
- }
- # Get the version of the downloaded installer
- $latestVersion = Get-FileVersion -filePath $downloadPath
- Write-Host "Installed Version: $installedVersion"
- Write-Host "Latest Version: $latestVersion"
- # Compare versions
- if ($installedVersion -eq $latestVersion) {
- Write-Host "The installed version is up to date. No update required."
- Remove-Item -Path $downloadPath -Force
- exit 0
- }
- # Stop the existing Power BI Gateway service
- try {
- Stop-Service -Name PBIEgwService -Force
- } catch {
- Write-Host "Failed to stop PBIEgwService: $_"
- exit 1
- }
- # Install the new Power BI Gateway
- try {
- Start-Process -FilePath $downloadPath -ArgumentList "/quiet" -Wait
- } catch {
- Write-Host "Installation failed: $_"
- exit 1
- }
- # Start the Power BI Gateway service
- try {
- Start-Service -Name PBIEgwService
- } catch {
- Write-Host "Failed to start PBIEgwService: $_"
- exit 1
- }
- # Cleanup the downloaded installer
- try {
- Remove-Item -Path $downloadPath -Force
- } catch {
- Write-Host "Cleanup failed: $_"
- exit 1
- }
- Write-Host "Power BI Gateway has been updated successfully."
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement