David Rigdon

Systems Administrator

PowerShell: Update PowerBI application | David Rigdon

PowerShell: Update PowerBI application

November 15, 2023

This script was created to allow for semi-automatic deployment of updates to PowerBI Desktop.

High Level Overview

Major Blockers creating the need for this script:

The only way to deploy an updated PowerBI application was the following manual process:

  1. Ensure that no users are connected to the session hosts, and enable drain mode on each machine before the update
  2. Grab the latest PowerBI installer from Microsoft
    • https://www.microsoft.com/en-us/download/details.aspx?id=58494
  3. Install the application either via the GUI or via the silent install options of “-quiet -norestart ACCEPT_EULA=1”
  4. Loop to the beginning until all session hosts are upgraded

Script Breakdown

This is by far one of my most favorite snippets… The first step in this script determines if it is running in an elevated session, and if not re-launches script to be elevated:

if (-Not ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] 'Administrator')) {
    if ([int](Get-CimInstance -Class Win32_OperatingSystem | Select-Object -ExpandProperty BuildNumber) -ge 6000) {
     $CommandLine = "-File `"" + $MyInvocation.MyCommand.Path + "`" " + $MyInvocation.UnboundArguments
     Start-Process -FilePath PowerShell.exe -Verb Runas -ArgumentList $CommandLine
     Exit
    }
   }

We next defined specific variables used in the script, specifically where we would download the file to, where to retrieve the file (note that the ugly full length powerBI url doesn’t change… ever.), and the combined installer path:

$TempFolderLocation = "C:\temp"
$PowerBIURL = "https://download.microsoft.com/download/8/8/0/880BCA75-79DD-466A-927D-1ABF1F5454B0/PBIDesktopSetup_x64.exe"
$installerPath = "$($TempFolderLocation)\PBIDesktopSetup_x64.exe"

This next snippet is another one of my favorite snippets, the simple if/then of checking to see if the temp folder exists

if (Test-Path $TempFolderLocation) {
   Write-Host "Temp Folder Exists, Continuing Installation."
}
else
{
    #Create the directory if not exists
    Write-Host "Temp Folder Does Not Exist, Creating."
    New-Item $TempFolderLocation -ItemType Directory
}

The final piece is to download and install the application, letting the user know what is happening during the process:

Write-host "Beginning Download of PowerBI"
Invoke-WebRequest -Uri $PowerBIURL -OutFile "$installerPath" -UseBasicParsing

## Run the downloaded file and update as necessary.
Write-Host "Download Complete, Beginning Installation."
Start-Process -FilePath $installerPath -ArgumentList "/q /norestart ACCEPT_EULA=1" -verb runas

Once this is done, we give the installer 10 minutes or so and then boom PowerBI is upgraded. Thought about creating a process to check for existing installed version and only installing if the version to be installed was newer, however that created some complexities I wasn’t willing to deal with.

This full script can be found here: Update-PowerBI-VDI.ps1