Modern SharePoint Online Programming - Chapter 1

Introduction 

 
Hi guys, let's explore a simple and crystal way to apply a custom theme with your company enterprise-level standard colors on a Modern SharePoint Site. It allows for a Hub site in order to have the same Custom Theme inherited automatically to all the Associated Sites, like connected Communication and Team sites. Therefore, this online PowerShell programming method is a good way to apply a Custom Theme. 
 
Just open the SharePoint Online Management Shell.
 
Run the below PS commands:
 
$Tenantsite="https://<EnterTenantName>-admin.sharepoint.com"
$cred = [System.Net.CredentialCache]::DefaultCredentials
[System.Net.WebRequest]::DefaultWebProxy.Credentials = $cred
Connect-SPOService -Url $Tenantsite
#Custom Enterprise Theme Generated Variable using the CSS file
$customTheme = @{
"themePrimary" = “#191940";
"themeLighterAlt" = “#ffffff";
"themeLighter" = "#f3f6f9";
"themeLight" = "#ffffff";
"themeTertiary" = "#627792";
"themeSecondary" = "#5795ff";
"themeDarkAlt" = "#0e2b5c";
"themeDark" = "#0e2b5c";
"themeDarker" = "#231834";
"neutralLighterAlt" = "#5795ff";
"neutralLighter" = "#f3f6f9";
"neutralLight" = "#5792ff";
"neutralQuaternaryAlt" = "#5792ff";
"neutralQuaternary" = "#f4f4f9";
"neutralTertiaryAlt" = "#c7cfda";
"neutralTertiary" = "#a8b5c6";
"neutralSecondary" = "#627792";
"neutralPrimaryAlt" = "#231834";
"neutralPrimary" = "#231834";
"neutralDark" = "#a8b5c6";
"black" = "#000000";
"white" = "#ffffff";
"primaryBackground" = "#5792ff";
"primaryText" = "#191937";
"bodyBackground" = "#5792ff";
"bodyText" = "#191937";
"disabledBackground" = "#a8b5c6";
"disabledText" = "#000000";
}
#You can define your standard approved custom colors using the https://www.color-hex.com/
Add-SPOTheme -Name "Custom Enterprise Theme" -Palette $customTheme -IsInverted $false –Overwrite
Get-SPOTheme
 
Once done, go to your Modern Hub site.
 
Click the Top Right Gear option>>Change the Look>> Theme>> Custom Enterprise Theme>>Save.
 
Hence the New above Custom Theme is applied on your Hub site and all the Associated sites to it shall also get reflected with the same change.
 
Note: The above process can be applied only on the Modern SharePoint Online Site collections only, as the above approach is using SP Online PS commands.
 
If you guys want to apply Custom Colors on your Modern SP On Prem Site collections, please refer to my previous blog: https://www.c-sharpcorner.com/blogs/how-to-apply-custom-theme-on-a-modern-sp-on-prem-2019-site.
 
Happy Modern SharePoint Development using PowerShell programming:)