Advertisement
Guest User

Untitled

a guest
Oct 6th, 2016
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.80 KB | None | 0 0
  1. function new-SPOnlineList {
  2. #variables that needs to be set before starting the script
  3. $siteURL = "https://***.sharepoint.com/sites/bsr"
  4. $adminUrl = "https://***-admin.sharepoint.com"
  5. $userName = "spoadmin@***.onmicrosoft.com"
  6. $listTitle = Read-Host "Please enter the name for the doc library"
  7. $listDescription = $listTitle
  8. $listTemplate = 101
  9.  
  10. # Let the user fill in their password in the PowerShell window
  11. $password = Read-Host "Please enter the password for $($userName)" -AsSecureString
  12.  
  13. # set SharePoint Online credentials
  14. $SPOCredentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($userName, $password)
  15.  
  16. # Creating client context object
  17. $context = New-Object Microsoft.SharePoint.Client.ClientContext($siteURL)
  18. $context.credentials = $SPOCredentials
  19.  
  20. #create list using ListCreationInformation object (lci)
  21. $lci = New-Object Microsoft.SharePoint.Client.ListCreationInformation
  22. $lci.title = $listTitle
  23. $lci.description = $listDescription
  24. $lci.TemplateType = $listTemplate
  25. $list = $context.web.lists.add($lci)
  26. $context.load($list)
  27. #send the request containing all operations to the server
  28. try{
  29. $context.executeQuery()
  30. write-host "info: Created $($listTitle)" -foregroundcolor green
  31. }
  32. catch{
  33. write-host "info: $($_.Exception.Message)" -foregroundcolor red
  34. }
  35.  
  36. #Load list and break inheritance
  37. $web = $context.web.Lists.GetByTitle($ListTitle)
  38. $context.load($web)
  39. $web.breakroleinheritance($false, $false)
  40. $web.update()
  41. #send the request containing all operations to the server
  42. try{
  43. $context.executeQuery()
  44. write-host "info: Broken inheritance for $($web.title)" -foregroundcolor green
  45. }
  46. catch{
  47. write-host "info: $($_.Exception.Message)" -foregroundcolor red
  48. }
  49. }
  50.  
  51. new-SPOnlineList
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement