Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function new-SPOnlineList {
- #variables that needs to be set before starting the script
- $siteURL = "https://***.sharepoint.com/sites/bsr"
- $adminUrl = "https://***-admin.sharepoint.com"
- $userName = "spoadmin@***.onmicrosoft.com"
- $listTitle = Read-Host "Please enter the name for the doc library"
- $listDescription = $listTitle
- $listTemplate = 101
- # Let the user fill in their password in the PowerShell window
- $password = Read-Host "Please enter the password for $($userName)" -AsSecureString
- # set SharePoint Online credentials
- $SPOCredentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($userName, $password)
- # Creating client context object
- $context = New-Object Microsoft.SharePoint.Client.ClientContext($siteURL)
- $context.credentials = $SPOCredentials
- #create list using ListCreationInformation object (lci)
- $lci = New-Object Microsoft.SharePoint.Client.ListCreationInformation
- $lci.title = $listTitle
- $lci.description = $listDescription
- $lci.TemplateType = $listTemplate
- $list = $context.web.lists.add($lci)
- $context.load($list)
- #send the request containing all operations to the server
- try{
- $context.executeQuery()
- write-host "info: Created $($listTitle)" -foregroundcolor green
- }
- catch{
- write-host "info: $($_.Exception.Message)" -foregroundcolor red
- }
- #Load list and break inheritance
- $web = $context.web.Lists.GetByTitle($ListTitle)
- $context.load($web)
- $web.breakroleinheritance($false, $false)
- $web.update()
- #send the request containing all operations to the server
- try{
- $context.executeQuery()
- write-host "info: Broken inheritance for $($web.title)" -foregroundcolor green
- }
- catch{
- write-host "info: $($_.Exception.Message)" -foregroundcolor red
- }
- }
- new-SPOnlineList
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement