Forum Discussion
Jörg Grimm
May 02, 2018Copper Contributor
SharePoint Online - PowerShell Apply Theme - Problem
Hello. I'm working on a PowerShell Script for SharePoint Online where I'm trying to apply a theme to a subsite with the following code:
$site.ApplyTheme($themeUrl,$null,$null,$false)
With the parameter $null for the fontSchemeUrl I always receive the Error: "The 'fontSchemeUrl' argument is invalid.".
Could somebody help me?
Thanks a lot.
- Piotrek Krakowiak
Microsoft
Hi Jörg,
this seems to be a quirk in how PowerShell treats the $null input versus the expected [String] parameter. SharePoint can deal with these 2 parameters being null but PowerShell is not happy about it.
I found 2 simple ways of resolving the issue:
1.Pass [NullString]::Value to the function call
$site.ApplyTheme($themeUrl, [NullString]::Value, [NullString]::Value, $false)
2. Pass Out-Null to the function call
$site.ApplyTheme($themeUrl, (Out-Null), (Out-Null), $false)
Both worked fine in my tests.
By the way - I am not a PowerShell expert (I am a SharePoint Developer) but I could find plenty of very complex discussions around passing $null to PowerShell functions - it seems that it is quite complex and not always fully intuitive.
Hope this helps!
Cheers,
Piotrek
- Jörg GrimmCopper Contributor
Hello Piotrek,
thank you very much. The Microsoft Support gave me the same solution, and now it works fine.
Cheers,
Jörg