Branding Kestrel Ridge University with Microsoft Graph and PowerShell
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.
- 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.
- Ridge Ink#13233F
- Kestrel Amber#F2B33D
- Slate Blue#4A6E94
- Graphite#3B4552
- Mist#EEF2F6
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.
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
squareLogosquareLogoDarkNot 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.
| No. | Flight | Destination | Cargo |
|---|---|---|---|
| Phase one | |||
| 01 | PATCH | /branding | application/json |
| Phase two | |||
| 02 | PUT | /branding | image/png |
| 03 | PUT | /branding | image/png |
| 04 | PUT | /branding | image/png |
| 05 | PUT | /branding | image/png |
| 06 | PUT | /branding | image/png |
| 07 | PUT | /branding | image/png |
| Verify | |||
| 08 | GET | /branding | None |
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.
- PowerShell
- Graph REST
# --- 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.'
PATCH https://graph.microsoft.com/v1.0/organization/{orgId}/branding
Content-Type: application/json
Accept-Language: 0
{
"backgroundColor": "#13233F",
"customPrivacyAndCookiesText": "Privacy & cookies",
"customPrivacyAndCookiesUrl": "https://philbryan.me/kru/kru-privacy.pdf",
"customTermsOfUseText": "Terms of use",
"customTermsOfUseUrl": "https://philbryan.me/kru/kru-terms.pdf",
"signInPageText": "Kestrel Ridge University lab tenant. All accounts and data are synthetic.",
"usernameHintText": "username@kestrelridgeu.philbryan.me",
"loginPageLayoutConfiguration": {
"layoutTemplateType": "default",
"isHeaderShown": true,
"isFooterShown": true
}
}
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.
- PowerShell
- Graph REST
# --- 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)"
}
PUT https://graph.microsoft.com/v1.0/organization/{orgId}/branding/localizations/0/bannerLogo
Content-Type: image/png
<the bytes of banner-logo-245x36.png>
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.
- PowerShell
- Graph REST
# --- Verify ---------------------------------------------------------------
$b = Invoke-MgGraphRequest GET $base -Headers $default
$b | Select-Object backgroundColor, customPrivacyAndCookiesUrl, customTermsOfUseUrl,
headerLogoRelativeUrl, bannerLogoRelativeUrl, squareLogoRelativeUrl,
squareLogoDarkRelativeUrl, faviconRelativeUrl, backgroundImageRelativeUrl | Format-List
GET https://graph.microsoft.com/v1.0/organization/{orgId}/branding
Accept-Language: 0
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.
Carry-on
Strings and settings
Like usernameHintText
Packed together into one PATCH
application/jsonChecked
Streams
Like backgroundImage
Checked one at a time, a PUT each
image/pngIn 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.
- 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
0 of 7 checked
<#
.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
