I have a Sharepoint 2010 Document Library with a range of subfolders and some files within each of them. The problem is, right now every subfolder has the same Modified timestamp, and I want each folder's Modified timestamp to be set to the latest Modified timestamp of the files inside.
My knowledge about the Object Model is pretty limited so far, and I'm having trouble writing a PowerShell script for this.
Here's my code so far:
$web = Get-SPWeb -Identity http://inside.site.be/Tools
$list = $web.GetList("http://inside.site.be/Tools/site_candidate/")
$folderquery = New-Object Microsoft.SharePoint.SPQuery
$foldercamlQuery =
'<Where>
<Eq>
<FieldRef Name="ContentType" />
<Value Type="text">Folder</Value>
</Eq>
</Where>'
$folderquery.Query = $foldercamlQuery
$folders = $list.GetItems($folderquery)
foreach($folder in $folders)
{
if($folder.ItemCount -gt 0){
$oldest = null
$filequery = New-Object Microsoft.SharePoint.SPQuery
$filequery.Folder = $folder
$files = SP.List.getItems($itemquery)
foreach ($file in $files){
if($file["Modified"] -ilt $oldest){$oldest = $file["Modified"]}
}
$folder["Modified"] = $oldest
$folder["Created"] = $oldest
$folder.Update()
Write-Host "$folder now has date $oldest"
} else {
Write-Warning "$folder['Name'] is empty"
}
}
I get the feeling I'm using the wrong types, but I've tried typecasting (for example, something like
foreach(Folder $folder in $folders){...}
But that doesn't seem to work. I've found pretty meager results about working with folders and files within in document libraries when searching for answers, maybe you guys can point me in the right direction?
Learning resources are also welcome.