-
Notifications
You must be signed in to change notification settings - Fork 0
/
Set Masterpage Recursively.ps1
52 lines (39 loc) · 2.48 KB
/
Set Masterpage Recursively.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# Script to set master pages of sites by recursive calls
# Works of site level
# Configuration variables
$SiteURL = "http://XXXXXXXXXX"
$MasterPageName = "MASTER-v2.master"
### DO NOT TOUCH THE CODE BELOW ###
# Required if not run in SharePoint Management Shell
if($ver.Version.Major -gt 1)
{
$Host.Runspace.ThreadOptions = "ReuseThread"
}
If((Get-PSSnapin -Name Microsoft.Sharepoint.Powershell -ErrorAction SilentlyContinue) -eq $null)
{
Add-PSSnapin Microsoft.Sharepoint.Powershell
}
Function GetAllWebs($URL)
{
$w = get-spweb $url
If($w.Webs.Count -gt 0)
{
Foreach($s in $w.Webs)
{
Write-Output "processing $($w.URL)" -Foregroundcolor Blue
$s.CustomMasterUrl = "/_catalogs/masterpage/$MasterPageName"
$s.MasterUrl = "/_catalogs/masterpage/$MasterPageName"
$s.Update()
GetAllWebs($s.URL)
}
}
$w.Dispose()
}
Function Set-MasterPage($URL)
{
Write-Output "processing $($w.URL)" -Foregroundcolor Blue
$s.CustomMasterUrl = "/_catalogs/masterpage/$MasterPageName"
$s.MasterUrl = "/_catalogs/masterpage/$MasterPageName"
$s.Update()
}
GetAllWebs($SiteURL)