Skip to content

Commit e31f9df

Browse files
authored
Merge pull request #5 from JakubPiegza/patch-6
Update ContentTypeManagementSubsitesIncluded.ps1
2 parents be7ca5c + 0f71c38 commit e31f9df

File tree

1 file changed

+39
-48
lines changed

1 file changed

+39
-48
lines changed

Content Types/Content Types Management Setting/Allow content type management for all lists in site collection/ContentTypeManagementSubsitesIncluded.ps1

Lines changed: 39 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -3,61 +3,52 @@
33
# Created by Arleta Wanat, 2015
44
#
55

6-
function Set-SPOListsContentTypesEnabled
7-
{
8-
param (
9-
[Parameter(Mandatory=$true,Position=1)]
6+
function Set-SPOListsContentTypesEnabled{
7+
param (
8+
[Parameter(Mandatory=$true,Position=1)]
109
[string]$Username,
1110
[Parameter(Mandatory=$true,Position=2)]
1211
[string]$AdminPassword,
13-
[Parameter(Mandatory=$true,Position=3)]
12+
[Parameter(Mandatory=$true,Position=3)]
1413
[string]$Url,
15-
[Parameter(Mandatory=$true,Position=4)]
14+
[Parameter(Mandatory=$true,Position=4)]
1615
[bool]$ContentTypesEnabled
17-
)
18-
19-
$password = ConvertTo-SecureString -string $AdminPassword -AsPlainText -Force
20-
$ctx=New-Object Microsoft.SharePoint.Client.ClientContext($Url)
21-
$ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username, $password)
22-
$ctx.ExecuteQuery()
23-
24-
$Lists=$ctx.Web.Lists
25-
$ctx.Load($ctx.Web)
26-
$ctx.Load($ctx.Web.Webs)
27-
$ctx.Load($Lists)
28-
$ctx.ExecuteQuery()
29-
30-
Foreach($ll in $Lists)
31-
{
32-
$ll.ContentTypesEnabled = $ContentTypesEnabled
33-
$ll.Update()
34-
35-
36-
try
37-
{
38-
$ctx.ExecuteQuery()
39-
Write-Host $ll.Title " Done" -ForegroundColor Green
40-
}
41-
42-
catch [Net.WebException]
43-
{
44-
45-
Write-Host "Failed" $_.Exception.ToString() -ForegroundColor Red
46-
}
16+
)
17+
18+
$password = ConvertTo-SecureString -string $AdminPassword -AsPlainText -Force
19+
$ctx=New-Object Microsoft.SharePoint.Client.ClientContext($Url)
20+
$ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username, $password)
21+
$ctx.ExecuteQuery()
22+
23+
$Lists=$ctx.Web.Lists
24+
$ctx.Load($ctx.Web)
25+
$ctx.Load($ctx.Web.Webs)
26+
$ctx.Load($Lists)
27+
$ctx.ExecuteQuery()
28+
29+
Foreach($ll in $Lists){
30+
$ll.ContentTypesEnabled = $ContentTypesEnabled
31+
$ll.Update()
32+
33+
try{
34+
$ctx.ExecuteQuery()
35+
Write-Host $ll.Title " Done" -ForegroundColor Green
36+
}
37+
catch [Net.WebException]{
38+
Write-Host "Failed" $_.Exception.ToString() -ForegroundColor Red
39+
}
40+
}
41+
42+
if($ctx.Web.Webs.Count -gt 0){
43+
Write-Host "--"-ForegroundColor DarkGreen
44+
45+
for($i=0;$i -lt $ctx.Web.Webs.Count ;$i++){
46+
Set-SPOListsContentTypesEnabled -Username $Username -Url $ctx.Web.Webs[$i].Url -AdminPassword $AdminPassword -ContentTypesEnabled $ContentTypesEnabled
47+
}
48+
}
4749

4850
}
4951

50-
if($ctx.Web.Webs.Count -gt 0)
51-
{
52-
Write-Host "--"-ForegroundColor DarkGreen
53-
for($i=0;$i -lt $ctx.Web.Webs.Count ;$i++)
54-
{
55-
Set-SPOListsContentTypesEnabled -Username $Username -Url $ctx.Web.Webs[$i].Url -AdminPassword $AdminPassword -ContentTypesEnabled $ContentTypesEnabled
56-
}
57-
}
58-
59-
}
60-
6152

6253

6354

@@ -80,4 +71,4 @@ $ContentTypesEnabled=$true
8071

8172

8273

83-
Set-SPOListsContentTypesEnabled -Username $Username -AdminPassword $AdminPassword -Url $Url -ContentTypesEnabled $ContentTypesEnabled
74+
Set-SPOListsContentTypesEnabled -Username $Username -AdminPassword $AdminPassword -Url $Url -ContentTypesEnabled $ContentTypesEnabled

0 commit comments

Comments
 (0)