Advertisement
Guest User

Untitled

a guest
Sep 20th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. [Reflection.Assembly]::LoadFile(([System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client").location))
  2. [Reflection.Assembly]::LoadFile(([System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client.runtime").location))
  3.  
  4.  
  5. Function Get-SPOContext([string]$Url,[string]$UserName,[string]$Password)
  6. {
  7. $SecurePassword = $Password | ConvertTo-SecureString -AsPlainText -Force
  8. $context = New-Object Microsoft.SharePoint.Client.ClientContext($Url)
  9. $context.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($UserName, $SecurePassword)
  10. return $context
  11. }
  12.  
  13. Function Get-ListItems([Microsoft.SharePoint.Client.ClientContext]$Context, [String]$ListTitle) {
  14. $list = $Context.Web.Lists.GetByTitle($listTitle)
  15. $qry = [Microsoft.SharePoint.Client.CamlQuery]::CreateAllItemsQuery()
  16. $items = $list.GetItems($qry)
  17. $Context.Load($items)
  18. $Context.ExecuteQuery()
  19. return $items
  20. }
  21.  
  22. $UserName = read-host "Please enter your name:"
  23. $PasswordReadHost = Read-Host -Prompt "Enter password" -AsSecureString
  24. $Password = [Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR($PasswordReadHost))
  25. $Url = "https://domain.sharepoint.com/"
  26. $ListTitle = "VMList"
  27. $context = Get-SPOContext -Url $Url -UserName $UserName -Password $Password
  28. $items = Get-ListItems -Context $context -ListTitle $ListTitle
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement