Guest User

Untitled

a guest
Nov 18th, 2016
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.43 KB | None | 0 0
  1. ############################################################################################################################################
  2. #Script that allows to create a new list in a SharePoint Online Site
  3. # Required Parameters:
  4. # -> $sUserName: User Name to connect to the SharePoint Online Site Collection.
  5. # -> $sPassword: Password for the user.
  6. # -> $sCSOMPath: CSOM Assemblies Path.
  7. # -> $sSiteUrl: SharePoint Online Site Url.
  8. # -> $sListName: Name of the list we are going to create.
  9. # -> $sListDescription: List description.
  10. ############################################################################################################################################
  11.  
  12. $host.Runspace.ThreadOptions = "ReuseThread"
  13.  
  14. #Definition of the function that allows to create a new view in a SharePoint Online list
  15. function Create-NewListSPO
  16. {
  17. param ($sCSOMPath,$sSiteUrl,$sUserName,$sPassword,$sListName,$sListDescription)
  18. try
  19. {
  20. #Adding the Client OM Assemblies
  21. $sCSOMRuntimePath=$sCSOMPath + "Microsoft.SharePoint.Client.Runtime.dll"
  22. $sCSOMPath=$sCSOMPath + "Microsoft.SharePoint.Client.dll"
  23. Add-Type -Path $sCSOMPath
  24. Add-Type -Path $sCSOMRuntimePath
  25.  
  26. #SPO Client Object Model Context
  27. $spoCtx = New-Object Microsoft.SharePoint.Client.ClientContext($sSiteUrl)
  28. $spoCredentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($sUserName, $sPassword)
  29. $spoCtx.Credentials = $spoCredentials
  30.  
  31. Write-Host "----------------------------------------------------------------------------" -foregroundcolor Green
  32. Write-Host "Creating List $sListName in $sSiteUrl !!" -ForegroundColor Green
  33. Write-Host "----------------------------------------------------------------------------" -foregroundcolor Green
  34.  
  35. $spoWeb=$spoCtx.Web
  36. $spoListCreationInformation=New-Object Microsoft.SharePoint.Client.ListCreationInformation
  37. $spoListCreationInformation.Title=$sListName
  38. #https://msdn.microsoft.com/EN-US/library/office/microsoft.sharepoint.client.listtemplatetype.aspx
  39. $spoListCreationInformation.TemplateType=[int][Microsoft.SharePoint.Client.ListTemplatetype]::DiscussionBoard
  40. $spoList=$spoWeb.Lists.Add($spoListCreationInformation)
  41. $spoList.Description=$sListDescription
  42. $spoCtx.ExecuteQuery()
  43.  
  44. Write-Host "----------------------------------------------------------------------------" -foregroundcolor Green
  45. Write-Host "Lsita $sListName created in $sSiteUrl !!" -ForegroundColor Green
  46. Write-Host "----------------------------------------------------------------------------" -foregroundcolor Green
  47. $spoCtx.Dispose()
  48. }
  49. catch [System.Exception]
  50. {
  51. Write-Host -ForegroundColor Red $_.Exception.ToString()
  52. }
  53. }
  54.  
  55. #Required Parameters
  56. $sSiteUrl = "https://<O365Domain>.sharepoint.com/<SPO_Site>"
  57. $sUserName = "<O365User>@<O365Domain>.onmicrosoft.com"
  58. $sListName= "<SPO_List_Name>"
  59. $sListDescription="<List Description>"
  60. #$sPassword = Read-Host -Prompt "Enter your password: " -AsSecureString
  61. $sPassword=ConvertTo-SecureString "<SPO_Password>" -AsPlainText -Force
  62. $sCSOMPath="<SPO_Path>"
  63.  
  64. Create-NewListSPO -sCSOMPath $sCSOMPath -sSiteUrl $sSiteUrl -sUserName $sUserName -sPassword $sPassword -sListName $sListName -sListDescription $sListDescription
Add Comment
Please, Sign In to add comment