0

I am trying to create a PowerShell script/function that will iterate through all the Document libraries (and folders within them) to set a column value on every file on the SharePoint site.

The column is called Archive. It is a Yes/No Column. How do I set the column to No ($false in PowerShell, I believe)?

  • Was there a specific question? – Graham Oct 17 '18 at 19:37
  • Sorry, I should have added that I am looking for a way to do this – TomB1 Oct 18 '18 at 10:48
1

The following PowerShell script for your reference.

##Variables for Processing
$SiteUrl = "https://lz.sharepoint.com/sites/lz"
$UserName="lz@lz.onmicrosoft.com"
$Password ="****"
$libraryName="DL"

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"

#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 
  • Thanks, does this look in folders though? – TomB1 Oct 18 '18 at 10:49
  • Yes, using "RecursiveAll" to get all items contains the folders and items in folders. – LZ_MSFT Oct 19 '18 at 1:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.