Skip to main content

Branding Kestrel Ridge University with Microsoft Graph and PowerShell

· 9 min read
Phil BryanAspiring IAM Engineer

The journey to becoming a Microsoft Identity and Access Administrator has begun, and it's already led me down an interesting path. The first step is company branding.

Flight SC-300Day 20 of 40
ADActive Directory
ENTRAMicrosoft Entra ID
Flying over
Kestrel Ridge University
Flown
19 days
To destination
21 days
Logged
Oct 23

Microsoft Learn has a quick three-minute article on configuring company branding. That got me thinking: could I take an arbitrary lab tenant and turn it into an environment where a school could be created, administered, and utilized for learning?

That inquiry turned out to be Kestrel Ridge University. One of the first things I did was leverage generative AI to create assets for this fictitious university: a logo, a banner, a colour palette, and a handful of other pieces I could use to brand my Microsoft tenant.

DestinationKRUKestrel Ridge UniversitySee further.
  • Ridge Ink#13233F
  • Kestrel Amber#F2B33D
  • Slate Blue#4A6E94
  • Graphite#3B4552
  • Mist#EEF2F6
kestrelridgeu.onmicrosoft.comBrand guide (PDF)

Instead of uploading those assets through the Entra portal, I followed lab rule 01 and wrote a PowerShell script that uses Microsoft Graph to upload them.

Into the Graph API documentation​

That naturally led me to the Microsoft Graph API documentation. In it, I found the organizationalBranding resource type, which lets me modify the different properties of company branding. I can read about the various properties and their relationships to locale, and I can update them to my liking.

Where each organizationalBranding property shows up on the sign-in page. Point at a property, or tap it, to find it on the sketch.

Strings and settings

Sent together, as JSON

Streams

Uploaded one image at a time

  • squareLogo squareLogoDarkNot on this page: they show in Windows setup (OOBE) and Autopilot

Using that, I built a PowerShell script that calls Microsoft Graph and pushes up the assets.

How the script works​

The script uses the Invoke-MgGraphRequest cmdlet to send requests that modifies our tenant's company branding.

The script runs in two phases.

Departuresgraph.microsoft.com/v1.0/organization/{orgId}
No.FlightDestinationCargo
Phase one
01PATCH/brandingapplication/json
Phase two
02PUT/branding/localizations/0/faviconimage/png
03PUT/branding/localizations/0/headerLogoimage/png
04PUT/branding/localizations/0/bannerLogoimage/png
05PUT/branding/localizations/0/squareLogoimage/png
06PUT/branding/localizations/0/squareLogoDarkimage/png
07PUT/branding/localizations/0/backgroundImageimage/png
Verify
08GET/brandingNone

Phase one: PATCH the metadata​

Phase one updates the branding "metadata": the background color, privacy URL, terms of use URL, sign-in page text, username hint text, and whether the header and footer are shown. All of that goes up in a single Invoke-MgGraphRequest PATCH call with an application/json content type.

Set-KruBranding.ps1
# --- Metadata: Text, color, layout -------------------------------------------------
$body = @{
backgroundColor = '#13233F'
customPrivacyAndCookiesText = 'Privacy & cookies'
customPrivacyAndCookiesUrl = $PrivacyUrl
customTermsOfUseText = 'Terms of use'
customTermsOfUseUrl = $TermsUrl
signInPageText = 'Kestrel Ridge University lab tenant. All accounts and data are synthetic.'
usernameHintText = 'username@kestrelridgeu.philbryan.me'
loginPageLayoutConfiguration = @{
layoutTemplateType = 'default'
isHeaderShown = $true
isFooterShown = $true
}
} | ConvertTo-Json -Depth 3

try {
Invoke-MgGraphRequest PATCH $base -Body $body -ContentType 'application/json' -Headers $default
} catch {
if ($_.Exception.Response.StatusCode -eq 'NotFound') {
throw 'No default branding object exists yet. Save the default sign-in experience once in the Entra admin center, then rerun.'
}
throw
}
Write-Host 'Text, color, and layout applied.'
The existence check

Lines 40 to 42: If the tenant has never saved a default branding object, there's nothing to patch and Graph answers 404 Not Found, so the script stops with a message that says what to do instead of a raw error.

Phase two: PUT each image​

Phase two handles the images. The script loops through each one and checks whether the file exists in my working folder. It throws a missing asset error if not found. If it's there, it sends an Invoke-MgGraphRequest PUT request with a content type of image/png.

Set-KruBranding.ps1
# --- Images (stream properties, uploaded one at a time) -------------------
$images = [ordered]@{
favicon = 'favicon-32.png'
headerLogo = 'header-logo-245x36.png'
bannerLogo = 'banner-logo-245x36.png'
squareLogo = 'square-logo-light-240.png'
squareLogoDark = 'square-logo-dark-240.png'
backgroundImage = 'background-1920x1080.png'
}
foreach ($prop in $images.Keys) {
$path = Join-Path $AssetDir $images[$prop]
if (-not (Test-Path $path)) { throw "Missing asset: $path" }
Invoke-MgGraphRequest PUT "$base/localizations/0/$prop" -InputFilePath $path -ContentType 'image/png'
Write-Host "Uploaded $prop ($([math]::Round((Get-Item $path).Length / 1KB, 1)) KB)"
}

Verify: GET it back​

Finally, the script verifies the results with a GET request, pulling down the object it just pushed up to confirm everything worked.

Set-KruBranding.ps1
# --- Verify ---------------------------------------------------------------
$b = Invoke-MgGraphRequest GET $base -Headers $default
$b | Select-Object backgroundColor, customPrivacyAndCookiesUrl, customTermsOfUseUrl,
headerLogoRelativeUrl, bannerLogoRelativeUrl, squareLogoRelativeUrl,
squareLogoDarkRelativeUrl, faviconRelativeUrl, backgroundImageRelativeUrl | Format-List

Why two phases?​

One constraint I ran into: Microsoft Graph won't let you update String properties (username hint text) and Stream properties (images) in the same request. That's why the script is split into two phases, one PATCH for the text-based settings and separate PUT requests for the images.

Baggage policy

Carry-on

Strings and settings

Like usernameHintText

Packed together into one PATCH

application/json

Checked

Streams

Like backgroundImage

Checked one at a time, a PUT each

image/png

In the words of the Microsoft Graph documentation: "You can't update Stream types with other data types in the same request."

What I learned​

Before I started developing this script, I didn't know you could use PowerShell to make API calls directly. I went hunting for cmdlets that would do what I needed, like Set-MgOrganizationBrandingBackgroundImage for changing the background image.

It turned out all I needed was to think in terms of HTTP requests: the right method, the right content type, and the right payload. Getting there took a lot of research, a lot of head-banging, and a lot of work figuring out how to do it efficiently.

What changed in how I work
  • Hunting for the right cmdlet to Thinking in HTTP requests
  • Clicking through the portal to Calling Microsoft Graph

I'm glad I discovered Invoke-MgGraphRequest. It means I can work out the calls I want in a tool like Postman or Microsoft Graph Explorer first, then use them in a PowerShell script.

The script​

Pre-flight checklistSet-KruBranding.ps1

0 of 7 checked

Set-KruBranding.ps1
<#
.SYNOPSIS
Applies Kestrel Ridge University company branding to the lab tenant via Microsoft Graph.
.NOTES
Scope: OrganizationalBranding.ReadWrite.All, Organization.Read.All
#>
#Requires -Modules Microsoft.Graph.Authentication
[CmdletBinding()]
param(
[string]$AssetDir = $PSScriptRoot,
[string]$PrivacyUrl = 'https://philbryan.me/kru/kru-privacy.pdf',
[string]$TermsUrl = 'https://philbryan.me/kru/kru-terms.pdf'
)
$ErrorActionPreference = 'Stop'

Connect-MgGraph -Scopes 'OrganizationalBranding.ReadWrite.All', 'Organization.Read.All' -NoWelcome
$orgId = (Get-MgOrganization).Id
$base = "https://graph.microsoft.com/v1.0/organization/$orgId/branding"
$default = @{ 'Accept-Language' = '0' } # locale 0 = default branding

# --- Metadata: Text, color, layout -------------------------------------------------
$body = @{
backgroundColor = '#13233F'
customPrivacyAndCookiesText = 'Privacy & cookies'
customPrivacyAndCookiesUrl = $PrivacyUrl
customTermsOfUseText = 'Terms of use'
customTermsOfUseUrl = $TermsUrl
signInPageText = 'Kestrel Ridge University lab tenant. All accounts and data are synthetic.'
usernameHintText = 'username@kestrelridgeu.philbryan.me'
loginPageLayoutConfiguration = @{
layoutTemplateType = 'default'
isHeaderShown = $true
isFooterShown = $true
}
} | ConvertTo-Json -Depth 3

try {
Invoke-MgGraphRequest PATCH $base -Body $body -ContentType 'application/json' -Headers $default
} catch {
if ($_.Exception.Response.StatusCode -eq 'NotFound') {
throw 'No default branding object exists yet. Save the default sign-in experience once in the Entra admin center, then rerun.'
}
throw
}
Write-Host 'Text, color, and layout applied.'

# --- Images (stream properties, uploaded one at a time) -------------------
$images = [ordered]@{
favicon = 'favicon-32.png'
headerLogo = 'header-logo-245x36.png'
bannerLogo = 'banner-logo-245x36.png'
squareLogo = 'square-logo-light-240.png'
squareLogoDark = 'square-logo-dark-240.png'
backgroundImage = 'background-1920x1080.png'
}
foreach ($prop in $images.Keys) {
$path = Join-Path $AssetDir $images[$prop]
if (-not (Test-Path $path)) { throw "Missing asset: $path" }
Invoke-MgGraphRequest PUT "$base/localizations/0/$prop" -InputFilePath $path -ContentType 'image/png'
Write-Host "Uploaded $prop ($([math]::Round((Get-Item $path).Length / 1KB, 1)) KB)"
}

# --- Verify ---------------------------------------------------------------
$b = Invoke-MgGraphRequest GET $base -Headers $default
$b | Select-Object backgroundColor, customPrivacyAndCookiesUrl, customTermsOfUseUrl,
headerLogoRelativeUrl, bannerLogoRelativeUrl, squareLogoRelativeUrl,
squareLogoDarkRelativeUrl, faviconRelativeUrl, backgroundImageRelativeUrl | Format-List

Follow along​