1

I am trying to apply a custom theme color to my SharePoint online site from an article I got online. Im running it in SharePoint online Management shell. I have the latest version of SPO management shell, it shows: vti_encoding:SR|utf8-nl vti_extenderversion:SR|16.0.0.12003 I've run the: Install-Module SharePointPnPPowerShellOnline cmd line I've also run the following: Set-ExecutionPolicy RemoteSigned -Force but I get the following error:
Connect-SPOService : The term 'Connect-SPOService' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
AND
Add-SPOTheme : The term 'Add-SPOTheme' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again

My script looks like this:

    $SPThemeName = "My Custom colors"

$SPThemePalette = const myTheme = @{
"themePrimary" = "#5d5daf";
"themeLighterAlt" = "#f7f7fc";
"themeLighter" = "#e0e0f2";
"themeLight" = "#c7c7e7";
"themeTertiary" = "#9595d0";
"themeSecondary" = "#6d6db9";
"themeDarkAlt" = "#54549e";
"themeDark" = "#474786";
"themeDarker" = "#343463";
"neutralLighterAlt" = "#faf9f8";
"neutralLighter" = "#f3f2f1";
"neutralLight" = "#edebe9";
"neutralQuaternaryAlt" = "#e1dfdd";
"neutralQuaternary" = "#d0d0d0";

"neutralTertiaryAlt" = "#c8c6c4"; "neutralTertiary" = "#a19f9d"; "neutralSecondary" = "#605e5c"; "neutralSecondaryAlt" = "#8a8886"; "neutralPrimaryAlt" = "#3b3a39"; "neutralPrimary" = "#323130"; "neutralDark" = "#201f1e"; "black" = "#000000"; "white" = "#ffffff"; }

Set-ExecutionPolicy RemoteSigned -Force

cls
if(Get-module -ListAvailable -Name "Microsoft.Online.SharePoint.PowerShell") {
    Write-Host "SharePoint Online module already installed" -ForegroundColor Green
}
else {
    Write-Host "Installing latest version of SharePoint Online module" -ForegroundColor Yellow
    Install-Module -Name Microsoft.Online.SharePoint.PowerShell -Force
}

Connect-SPOService -Url <myURL> -credential <myUsername>

Add-SPOTheme -Identity $SPThemeName -Palette $SPThemePalette -IsInverted $false

Write-Host "Your Fluent UI Theme '"$SPThemeName "' is now added to SharePoint.`n Go to a web site and Change the Look." -ForegroundColor Green

Set-ExecutionPolicy Default -Force

Import-Module -Name Microsoft.Online.SharePoint.PowerShell - It says it is already installed

I'm running this in Windows Powershell ISE with admin privileges. I'm importing the SharePoint Online Man module, but it still tells me the term Connect-SPOService and Add-SPOTheme is not recognized
Please Help?

2
  • Try using latest version 16.0.23408.12000. let me know if this works for you. Mar 16, 2023 at 14:45
  • I've installed the SPO Manament Powershell and it says: Microsoft.Online.SharePoint.PowerShell 16.0.23408.12000 But still give same error
    – Hes JvR
    Mar 16, 2023 at 14:59

2 Answers 2

1

Your script is connecting to SharePoint using a cmdlet from the PnP.PowerShell module but is then using the Add-SPOTheme cmdlet from the Microsoft.Online.SharePoint.PowerShell module.

To connect to SharePoint using Microsoft.Online.SharePoint.PowerShell, you should use Connect-SPOService.

Additionally, make sure the PowerShell module is loaded by using Import-Module at the start of your script:

Import-Module -Name Microsoft.Online.SharePoint.PowerShell 
6
  • Thank you Callum. I have installed the SharePoint Online management shell and tried to run only the command: Connect-SPOService there. It says the term Connect-SPOService is not recognized as the name of a cmdlet, function ect. What am I missing here?
    – Hes JvR
    Mar 22, 2023 at 5:56
  • Did you include the "Import-Module" line at the start of your script? Mar 22, 2023 at 9:53
  • I've edited my original question with the full script
    – Hes JvR
    Mar 22, 2023 at 14:07
  • Your script doesn't use Import-Module, we're not questioning whether it is installed but whether it has been imported to the current session. Mar 22, 2023 at 14:32
  • Apologies, the first line was not copied - I start the script with Import-Module -Name Microsoft.Online.SharePOint.Powershell.
    – Heste
    Mar 23, 2023 at 9:16
0

I found a very nice solution on SharePointDiary.com that uses Powershell script (not SPO Man shell) - It works perfectly.

#Define the color palette $ThemePalette = @{ "themePrimary" = "#00d492"; "themeLighterAlt" = "#f3fdfa"; "themeLighter" = "#d0f8eb"; "themeLight" = "#a9f2db"; "themeTertiary" = "#5ce5b9"; "themeSecondary" = "#1ad99c"; "themeDarkAlt" = "#00be82"; "themeDark" = "#00a16e"; "themeDarker" = "#007751"; "neutralLighterAlt" = "#f8f8f8"; "neutralLighter" = "#f4f4f4"; "neutralLight" = "#eaeaea"; "neutralQuaternaryAlt" = "#dadada"; "neutralQuaternary" = "#d0d0d0"; "neutralTertiaryAlt" = "#c8c8c8"; "neutralTertiary" = "#ae9e9e"; "neutralSecondary" = "#938181"; "neutralPrimaryAlt" = "#796767"; "neutralPrimary" = "#0f0b0b"; "neutralDark" = "#443636"; "black" = "#2a2020"; "white" = "#ffffff"; }
#Set Admin Center URL $AdminCenterURL = ""
#Connect to SharePoint Online - Prompt for credentials Connect-SPOService -url $AdminCenterURL -Credential (Get-Credential)
#Add new SharePoint Online theme Add-SPOTheme -Name "Theme name" -Palette $ThemePalette -IsInverted $False

#Read more: https://www.sharepointdiary.com/2017/11/sharepoint-online-add-custom-theme-using-powershell.html#ixzz7wm0mJBJt

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.