Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ##Variables for Processing
- $SiteUrl = "https://lz.sharepoint.com/sites/lz"
- $UserName="lz@lz.onmicrosoft.com"
- $Password ="****"
- $libraryName="DL"
- Add-Type -Path "c:Program FilesCommon Filesmicrosoft sharedWeb Server Extensions16ISAPIMicrosoft.SharePoint.Client.dll"
- Add-Type -Path "c:Program FilesCommon Filesmicrosoft sharedWeb Server Extensions16ISAPIMicrosoft.SharePoint.Client.Runtime.dll"
- #Setup Credentials to connect
- $Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($UserName,(ConvertTo-SecureString $Password -AsPlainText -Force))
- #Setup the context
- $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
- $Ctx.Credentials = $Credentials
- $Web = $Ctx.web
- #Get the List
- $List = $Ctx.Web.Lists.GetByTitle($libraryName)
- $Ctx.Load($List)
- $Ctx.ExecuteQuery()
- #Get All List items
- $ListItemsCAML = New-Object Microsoft.SharePoint.Client.CamlQuery
- $ListItemsCAML.ViewXml = "<View Scope='RecursiveAll'></View>"
- $ListItems = $List.GetItems($ListItemsCAML)
- $Ctx.Load($ListItems)
- $Ctx.ExecuteQuery()
- Write-host "Total Items Found:"$List.ItemCount
- #Iterate through each item and update
- Foreach ($ListItem in $ListItems)
- {
- #Set New value for List column
- $ListItem["Archive"] = $false
- $ListItem.Update()
- $Ctx.ExecuteQuery()
- }
- Write-host "All Items in the Library: $libraryName Updated Successfully!" -ForegroundColor Green
Add Comment
Please, Sign In to add comment