Title: Update List items
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"
$SiteURL="https://hpeblore.sharepoint.com/sites/Omi"
$ListName="Employee"
Try {
$Cred= Get-Credential
$Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)
#Setup the context
$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$Ctx.Credentials = $Credentials
$Web = $Ctx.web
#Get and load the List
$List = $Ctx.Web.Lists.GetByTitle($ListName)
$Ctx.Load($List)
$Ctx.ExecuteQuery()
#Get All List items
$CAMLQuery = New-Object Microsoft.SharePoint.Client.CamlQuery
$CAMLQuery.ViewXml = "<View></View>"
$ListItems = $List.GetItems($CAMLQuery)
$Ctx.Load($ListItems)
$Ctx.ExecuteQuery()
#Write-host $List.ItemCount
Foreach ($ListItem in $ListItems)
{
if($ListItem["Title"] -eq "Bramhendra")
{
$ListItem["Location"] = "Banaglore"
#write-host $ListItem["ID"]
$ListItem.Update()
$Ctx.ExecuteQuery()
}
}
}
Catch {
write-host -f Red "Error Updating List Items!" $_.Exception.Message
}