Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
$UserName= "***@xxzz.onmicrosoft.com"
$Password = "***"
$credentials= New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($UserName,(ConvertTo-SecureString $Password -AsPlainText -Force))
$webURL="https://xxzz.sharepoint.com/sites/Team"
$ctx= New-Object Microsoft.SharePoint.Client.ClientContext($webURL)
$ctx.Credentials = $credentials
try{
$lists = $ctx.web.Lists
$list = $lists.GetByTitle("TestList")
$listItems = $list.GetItems([Microsoft.SharePoint.Client.CamlQuery]::CreateAllItemsQuery())
$ctx.load($listItems)
$ctx.executeQuery()
foreach($listItem in $listItems)
{
Write-Host "ID - " $listItem["ID"] "Title - " $listItem["Title"] "DateTime - " $listItem["DateTime"] "Choices - " $listItem["Choices"]
}
}
catch{
write-host "$($_.Exception.Message)" -foregroundcolor red
}
For look up columns:
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
$UserName= "***@xxzz.onmicrosoft.com"
$Password = "***"
$credentials= New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($UserName,(ConvertTo-SecureString $Password -AsPlainText -Force))
$webURL="https://xxzz.sharepoint.com/sites/Team"
$ctx= New-Object Microsoft.SharePoint.Client.ClientContext($webURL)
$ctx.Credentials = $credentials
try{
$lists = $ctx.web.Lists
$list = $lists.GetByTitle("TestList")
$listItems = $list.GetItems([Microsoft.SharePoint.Client.CamlQuery]::CreateAllItemsQuery())
$ctx.load($listItems)
$ctx.executeQuery()
foreach($listItem in $listItems)
{
Write-Host "ID - " $listItem["ID"] "Title - " $listItem["Title"] "DateTime - " $listItem["DateTime"] "Choices - " $listItem["Choices"]
}
}
catch{
write-host "$($_.Exception.Message)" -foregroundcolor red
}
For look up columns:
$lookup = [Microsoft.SharePoint.Client.FieldLookupValue]$listItem["Lookup"]
$lookupValue=$lookup.LookupValue
No comments:
Post a Comment