Hey all, i’m looking for some scripting help.
Basically what I am trying to do is get all Site Collections under a specific Web Application, then apply the properties for MasterUrl, CustomMasterUrl and AlternateCssUrl.
Here is the script I have, which is not working as it tells me ‘The Properties do not exist’:
Get-SPSite -ContentDatabase SP_CONTENT | foreach-object {
$_.MasterUrl = “/_catalogs/masterpage/cs1_sp2010.master”
$_.CustomMasterUrl = “/_catalogs/masterpage/cs1_sp2010.master”
$_.alternatecssurl = “/Style Library/cs1_sp2010.css”;
$_.Update()
}
When executing Get-SPSite -ContentDatabase SP_CONTENT, I receive the list of site collections (which is approximately 15 in this case). Results of the Get statement below:
Url
—
http://web.site.com
http://web.site.com/app/branding
http://web.site.com/app/bree
http://web.site.com/app/carrepairs
http://web.site.com/app/invoicing
http://web.site.com/app/sctrack
http://web.site.com/dept/Equip
http://web.site.com/dept/Finance
http://web.site.com/dept/FM
http://web.site.com/dept/HR
http://web.site.com/dept/IT
http://web.site.com/dept/it/pmo
http://web.site.com/dept/Laws
http://web.site.com/dept/QA
http://web.site.com/dept/QITS
http://web.site.com/dept/SRStuff
When executing the full PowerShell script in blue above, here are the errors received:
Property ‘MasterUrl’ cannot be found on this object; make sure it exists and is
settable.
At E:\scripts\Branding\Branding-AAA-TEST-Apply_MasterPages_CSS_to_INSIDEQA_Site
s.ps1:2 char:8
+ $_. <<<< MasterUrl = “/_catalogs/masterpage/cs1_sp2010.master”
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : PropertyAssignmentException
Property ‘CustomMasterUrl’ cannot be found on this object; make sure it exists
and is settable.
At E:\scripts\Branding\Branding-AAA-TEST-Apply_MasterPages_CSS_to_INSIDEQA_Site
s.ps1:3 char:8
+ $_. <<<< CustomMasterUrl = “/_catalogs/masterpage/cs1_sp2010.master”
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : PropertyAssignmentException
Property ‘alternatecssurl’ cannot be found on this object; make sure it exists
and is settable.
At E:\scripts\Branding\Branding-AAA-TEST-Apply_MasterPages_CSS_to_INSIDEQA_Site
s.ps1:4 char:8
+ $_. <<<< alternatecssurl = “/Style Library/cs1_sp2010.css”;
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : PropertyAssignmentException
Method invocation failed because [Microsoft.SharePoint.SPSite] doesn’t contain
a method named ‘Update’.
At E:\scripts\Branding\Branding-AAA-TEST-Apply_MasterPages_CSS_to_INSIDEQA_Site
s.ps1:5 char:14
+ $_.Update <<<< ()
+ CategoryInfo : InvalidOperation: (Update:String) [], RuntimeExc
eption
+ FullyQualifiedErrorId : MethodNotFound
Any help is appreciated, thanks!
Fixed a bit. didn’t test!
$Sites = Get-SPSite -ContentDatabase SPPRD_PORTAL_CONTENT1
foreach ($site in $sites)
{
$web = Get-SPWeb $site.url
if ($site.url -eq “http://web.site.com/app/avepoint”)
{
$web.MasterUrl = “/_catalogs/masterpage/v4.master”;
$web.CustomMasterUrl = “/_catalogs/masterpage/v4.master”;
$web.Update()
}
else {
$cssurl = $web.Url + “/Style%20Library/cs1_sp2010.css”;
$web.MasterUrl = “/_catalogs/masterpage/cs1_sp2010.master”;
$web.CustomMasterUrl = “/_catalogs/masterpage/cs1_sp2010.master”;
$web.AlternateCssUrl = $cssurl
$web.Update() }
}
Hey Vlad,
Check this out pls:
$Webapp = Get-SPWebApplication “http://web.site.com”
$Sites = Get-SPSite -ContentDatabase SPPRD_PORTAL_CONTENT1
foreach ($site in $sites)
{
$web = Get-SPWeb $site.url
if ($site.url -eq “http://web.site.com/app/avepoint)
{
$web.MasterUrl = “/_catalogs/masterpage/v4.master”;
$web.CustomMasterUrl = “/_catalogs/masterpage/v4.master”;
}
else {
$cssurl = $web.Url + “/Style%20Library/cs1_sp2010.css”;
$web.MasterUrl = “/_catalogs/masterpage/cs1_sp2010.master”;
$web.CustomMasterUrl = “/_catalogs/masterpage/cs1_sp2010.master”;
$web.AlternateCssUrl = $cssurl }
Write-Host $cssurl
$web.Update()
On a second look, I found your error in the original script.
Get-SPSite -ContentDatabase SP_CONTENT | foreach-object { Â <<< You are getting every SPSite.Â
The Properties you are trying to push are for the SPWeb class ! Â Thats why it doesn’t find the property!
Hi Andre, I tried this and it works on SharePoint 2013.
$Webapp = Get-SPWebApplication “http://collab.vicdev.ca”
$Sites = $Webapp.sites.url
foreach ($site in $sites)
{
$web = Get-SPWeb $site
$cssurl = $web.url + “/Shared%20Documents/theme.css”
$web.AlternateCssUrl = $cssurl
Write-Host $cssurl
$web.Update()
}
No go Vlad. Here is the error:
PS E:\scripts\Branding> .\Branding-AAA-TEST-Apply_MasterPages_CSS_to_INSIDEQA_Si
tes.ps1
Exception calling “Update” with “0” argument(s): “Specified data type does not
match the current data type of the property.”
At E:\scripts\Branding\Branding-AAA-TEST-Apply_MasterPages_CSS_to_INSIDEQA_Site
s.ps1:7 char:12
+ $web.Update <<<< ()
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException