PowerShell: Update PowerBI application
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:
- At the time of this documentation (November 2023) UWP / Store Apps do not function properly with FSLogix Profiles, therefore using MSIX attach to install the application will not work.
- At the time, there was also an issue that because these particular machines were running in Azure VDI pools, they were identified to our patch management platform as “Windows 10 Enterprise for Virtual Desktops” and so the patching application could not correctly identify and then install applications.
- Updates are released monthly, and the users of the environment would like to run on the latest version of the application.
The only way to deploy an updated PowerBI application was the following manual process:
- Ensure that no users are connected to the session hosts, and enable drain mode on each machine before the update
- Grab the latest PowerBI installer from Microsoft
- https://www.microsoft.com/en-us/download/details.aspx?id=58494
- Install the application either via the GUI or via the silent install options of “-quiet -norestart ACCEPT_EULA=1”
- 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