Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ $Url="https://trialtrial123.sharepoint.com/sites/teamsitewithlists"
$ContentTypesEnabled=$true
```

###Please share your thoughts in the Q&A section!
### Please share your thoughts in the Q&A section!

####Related scripts</br>
#### Related scripts</br>
[Set direction of the reading order for a single list](https://gallery.technet.microsoft.com/office/Set-SPOList-properties-9d16f2ba)

[Set-SPOList properties (module)](https://gallery.technet.microsoft.com/scriptcenter/Disable-or-enable-12cf3795)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,61 +3,52 @@
# Created by Arleta Wanat, 2015
#

function Set-SPOListsContentTypesEnabled
{
param (
[Parameter(Mandatory=$true,Position=1)]
function Set-SPOListsContentTypesEnabled{
param (
[Parameter(Mandatory=$true,Position=1)]
[string]$Username,
[Parameter(Mandatory=$true,Position=2)]
[string]$AdminPassword,
[Parameter(Mandatory=$true,Position=3)]
[Parameter(Mandatory=$true,Position=3)]
[string]$Url,
[Parameter(Mandatory=$true,Position=4)]
[Parameter(Mandatory=$true,Position=4)]
[bool]$ContentTypesEnabled
)

$password = ConvertTo-SecureString -string $AdminPassword -AsPlainText -Force
$ctx=New-Object Microsoft.SharePoint.Client.ClientContext($Url)
$ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username, $password)
$ctx.ExecuteQuery()

$Lists=$ctx.Web.Lists
$ctx.Load($ctx.Web)
$ctx.Load($ctx.Web.Webs)
$ctx.Load($Lists)
$ctx.ExecuteQuery()

Foreach($ll in $Lists)
{
$ll.ContentTypesEnabled = $ContentTypesEnabled
$ll.Update()


try
{
$ctx.ExecuteQuery()
Write-Host $ll.Title " Done" -ForegroundColor Green
}

catch [Net.WebException]
{

Write-Host "Failed" $_.Exception.ToString() -ForegroundColor Red
}
)

$password = ConvertTo-SecureString -string $AdminPassword -AsPlainText -Force
$ctx=New-Object Microsoft.SharePoint.Client.ClientContext($Url)
$ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username, $password)
$ctx.ExecuteQuery()

$Lists=$ctx.Web.Lists
$ctx.Load($ctx.Web)
$ctx.Load($ctx.Web.Webs)
$ctx.Load($Lists)
$ctx.ExecuteQuery()

Foreach($ll in $Lists){
$ll.ContentTypesEnabled = $ContentTypesEnabled
$ll.Update()

try{
$ctx.ExecuteQuery()
Write-Host $ll.Title " Done" -ForegroundColor Green
}
catch [Net.WebException]{
Write-Host "Failed" $_.Exception.ToString() -ForegroundColor Red
}
}

if($ctx.Web.Webs.Count -gt 0){
Write-Host "--"-ForegroundColor DarkGreen

for($i=0;$i -lt $ctx.Web.Webs.Count ;$i++){
Set-SPOListsContentTypesEnabled -Username $Username -Url $ctx.Web.Webs[$i].Url -AdminPassword $AdminPassword -ContentTypesEnabled $ContentTypesEnabled
}
}

}

if($ctx.Web.Webs.Count -gt 0)
{
Write-Host "--"-ForegroundColor DarkGreen
for($i=0;$i -lt $ctx.Web.Webs.Count ;$i++)
{
Set-SPOListsContentTypesEnabled -Username $Username -Url $ctx.Web.Webs[$i].Url -AdminPassword $AdminPassword -ContentTypesEnabled $ContentTypesEnabled
}
}

}




Expand All @@ -80,4 +71,4 @@ $ContentTypesEnabled=$true



Set-SPOListsContentTypesEnabled -Username $Username -AdminPassword $AdminPassword -Url $Url -ContentTypesEnabled $ContentTypesEnabled
Set-SPOListsContentTypesEnabled -Username $Username -AdminPassword $AdminPassword -Url $Url -ContentTypesEnabled $ContentTypesEnabled
Original file line number Diff line number Diff line change
@@ -1,29 +1,17 @@
A short Powershell script to allow management of content types for all SharePoint Online lists and libraries across all sites in a site collection



It is an equivalent of List>>List Settings>>Advanced>>Content types in Graphic User Interface (see screenshot)







It is an equivalent of **List**>>**List Settings**>>**Advanced**>>**Content types in Graphic User Interface** ([see screenshot](https://github.com/PowershellScripts/AllGalleryScriptsSamples/blob/develop/Content%20Types/Content%20Types%20Management%20Setting/Allow%20content%20type%20management%20for%20all%20lists%20in%20site%20collection/contentTypeManagement.png))


Applies to lists and libraries.





It requires installed SharePoint Online SDK
*It requires installed* [SharePoint Online SDK](www.microsoft.com/en-us/download/details.aspx?id=42038)

You have to enter the list information before running the script:



```PowerShell

# Paths to SDK. Please verify location on your computer.
Expand All @@ -36,33 +24,26 @@ $AdminPassword="Pass"
$Url="https://trialtrial123.sharepoint.com/sites/teamsitewithlists"
$ContentTypesEnabled=$true
```






Please share your thoughts in the Q&A section!


### Please share your thoughts in the Q&A section!

Wiki article with detailed code description:
#### Wiki article with detailed code description:


[SharePoint Online: Turn on support for multiple content types in a list or library using Powershell](http://social.technet.microsoft.com/wiki/contents/articles/30038.sharepoint-online-turn-on-support-for-multiple-content-types-in-a-list-or-library-using-powershell.aspx)



Related scripts
Set-SPOList properties (module)
#### Related scripts
[Set-SPOList properties (module)](https://gallery.technet.microsoft.com/office/Set-SPOList-properties-9d16f2ba)

Disable or enable attachments to list items using Powershell
[Disable or enable attachments to list items using Powershell](https://gallery.technet.microsoft.com/scriptcenter/Disable-or-enable-12cf3795)

Change search setting for all lists in a site using CSOM and Powershell
[Change search setting for all lists in a site using CSOM and Powershell](https://gallery.technet.microsoft.com/scriptcenter/Change-search-setting-for-8e842a48)

Allow content type management for all lists in a site using Powershell
[Allow content type management for all lists in a site using Powershell](https://gallery.technet.microsoft.com/scriptcenter/Allow-content-type-5bca5157)

Set content type management setting for SharePoint Online list using Powershell
[Set content type management setting for SharePoint Online list using Powershell](https://gallery.technet.microsoft.com/scriptcenter/Set-content-type-39ae4bce)


<br/><br/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,58 +3,45 @@
# Created by Arleta Wanat, 2015
#

function Set-SPOList
{
param (
[Parameter(Mandatory=$true,Position=0)]
function Set-SPOList{
param(
[Parameter(Mandatory=$true,Position=0)]
[string]$ListName,
[Parameter(Mandatory=$true,Position=1)]
[Parameter(Mandatory=$true,Position=1)]
[bool]$ContentTypesEnabled
)
)

$ll=$ctx.Web.Lists.GetByTitle($ListName)
$ll=$ctx.Web.Lists.GetByTitle($ListName)

$ll.ContentTypesEnabled = $ContentTypesEnabled
$ll.Update()

try
{
$ctx.ExecuteQuery()
Write-Host "Done" -ForegroundColor Green
}

catch [Net.WebException]
{

Write-Host "Failed" $_.Exception.ToString() -ForegroundColor Red
}

$ll.ContentTypesEnabled = $ContentTypesEnabled
$ll.Update()

try{
$ctx.ExecuteQuery()
Write-Host "Done" -ForegroundColor Green
}
catch [Net.WebException]{
Write-Host "Failed" $_.Exception.ToString() -ForegroundColor Red
}
}




function Connect-SPOCSOM
{
param (
[Parameter(Mandatory=$true,Position=1)]
function Connect-SPOCSOM{
param(
[Parameter(Mandatory=$true,Position=1)]
[string]$Username,
[Parameter(Mandatory=$true,Position=2)]
[string]$AdminPassword,
[Parameter(Mandatory=$true,Position=2)]
[Parameter(Mandatory=$true,Position=2)]
[string]$Url
)
)


$password = ConvertTo-SecureString -string $AdminPassword -AsPlainText -Force
$ctx=New-Object Microsoft.SharePoint.Client.ClientContext($Url)
$ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username, $password)
$ctx.ExecuteQuery()
$global:ctx=$ctx
$password = ConvertTo-SecureString -string $AdminPassword -AsPlainText -Force
$ctx=New-Object Microsoft.SharePoint.Client.ClientContext($Url)
$ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username, $password)
$ctx.ExecuteQuery()
$global:ctx=$ctx
}


$global:ctx


Expand All @@ -77,4 +64,4 @@ $ContentTypesEnabled =$false

Connect-SPOCSOM -Username $Username -AdminPassword $AdminPassword -Url $Url

Set-SPOList -ListName $ListName -ContentTypesEnabled $ContentTypesEnabled
Set-SPOList -ListName $ListName -ContentTypesEnabled $ContentTypesEnabled
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,9 @@ http://social.technet.microsoft.com/wiki/contents/articles/31051.sharepoint-onli

### How to use?

1. Download and install [SharePoint Online SDK](https://www.microsoft.com/en-us/download/details.aspx?id=42038).


1. Download and install SharePoint Online SDK.

2. Download the .ps1 file.
2. Download the *.ps1* file.

3. Open the file (you can do it also in NotePad)

Expand All @@ -33,15 +31,14 @@ $Name="Name of the Content Type2"
$ParentContentTypeID="0x01"
$Group="List Content Types"
```
a) Find on your computer where SharePoint.Clitent.dll and SharePoint.Client.Runtime.dll libraries are located and insert the correct paths
b) Instead of "admin@tenant.onmicrosoft.com" enter you username
c) Instead of "https://tenant.sharepoint.com/sites/teamsitewithlibraries" enter the name of the site collection where you want to find the content types
d) Fill in the properties of the content type.
a) Find on your computer where SharePoint.Clitent.dll and SharePoint.Client.Runtime.dll libraries are located and insert the correct paths</br>
b) Instead of "admin@tenant.onmicrosoft.com" enter you username</br>
c) Instead of "https://tenant.sharepoint.com/sites/teamsitewithlibraries" enter the name of the site collection where you want to find the content types</br>
d) Fill in the properties of the content type.</br>


5. Run the script in Powershell (any module).

6. When the script has executed, Powershell will show a message Content Type Name of the Content Type2 has been added to Title of the List.
6. When the script has executed, Powershell will show a message *Content Type Name of the Content Type2 has been added to Title of the List*.

<br/><br/>
<b>Enjoy and please share feedback!</b>
Loading