There are several ways a theme can be applied to a SharePoint site.
Set-SPOTheme -ColorPaletteUrl $PathThemeColor -FontSchemeUrl $PathThemeFont
Unfortunately I was getting message ‘Field or property “AlternateCssUrl” does not exist.’
The error is due not having latest patch installed. Unfortunately the latest SharePoint CU can’t be installed as we have heavily customised legacy applications migrated from SharePoint 2007 and SharePoint 2010 running in compatibility mode.
The other option was to use the add-in “DeployCustomTheme” from PnP samples. However it meant deploying the add-in before applying the theme and add-in catalog has not been enabled on the SharePoint farm.
Using PnP PowerShell Commands the custom theme and master page files can be uploaded to folder “/_catalogs/theme/15” and “/_catalogs/masterpage” respectively.
Deploy Custom Color
Add-SPOFile -Path ".\Files\Themes\Palette_EDRMS.spcolor" -Folder "/_catalogs/theme/15"
Deploy Custom Font
Add-SPOFile -Path ".\Files\Themes\fontscheme_EDRMS.spfont" -Folder "/_catalogs/theme/15"
Deploy Custom Master Page html and preview
Add-SPOFile -Path ".\Files\Themes\MasterPage\seattle_edrms.html" -Folder "/_catalogs/masterpage"
Add-SPOFile -Path ".\Files\Themes\MasterPage\seattle_edrms.preview" -Folder "/_catalogs/masterpage"
After deploying the files, the custom theme can be applied using the PowerShell script below. The custom composed look is created before the theme is applied using the CSOM method “ApplyTheme”
After running script, the theme on the site is updated.