Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I have a Document Library in SP 2010 with a bunch of files organized into folders. Each file has the Last Modified timestamp and Created timestamp set to the time they were uploaded.

However, we need to have these timestamps set to those of the original files.

I still have the original files in a seperate location, but instead of being organized by folder everything is just thrown into one big filedump.

I thought about writing a PowerShell script to iterate through the Document Library searching for files with a modifieddate equal or greater then 2012, looking up each item's filename and looking up the Last Modified and Created-dates of the original file, then writing those values to the file in the Document Library. Here's my code that's supposed to do this:

$web = Get-SPWeb -Identity <removed for privacy reasons>
$list = $web.GetList("<removed for privacy reasons>")

<# I thought about writing a PowerShell script to iterate through the Document Library 
searching for files with a modifieddate equal or greater then 2012, #>

$query =  New-Object Microsoft.SharePoint.SPQuery 
$camlQuery = 
'<Query>
    <Where>
        <Geq>
            <FieldRef Name="Created" />
            <Value IncludeTimeValue="TRUE" Type="DateTime">
                2012-01-01T00:00:01Z
            </Value>
        </Geq>
    </Where>
</Query>'
$query.ViewAttributes = 'Scope="Recursive"'
$query.Query = $camlQuery

<# looking up each item's filename #>

$items = $list.GetItems($query)


foreach($item in $items){
    $curfilename = $item.Name
    $curcreated = $item["Created"]
    $curmodified = $item["Modified"]

    <# and looking up the Last Modified and Created-dates of the original file, #> 
    $orgfilename = "\\<removed for privacy reasons>\$curfilename"
    $orgfile = Get-Item $orgfilename
    $orgcreated = $orgfile.LastWriteTime
    $orgmodified = $orgfile.CreationTime

    if($orgcreated -gt $orgmodified) 
    {
        $oldestdate = $orgmodified
    } else {
        $oldestdate = $orgcreated
    }

    <# then writing those values to the file in the Document Library. #>
    $item.["Created"] = $oldestdate;
    $item.["Modified"] = $oldestdate;
    $item.UpdateOverwriteVersion();
    Write-Host "Item: $curfilename Org: $curcreated New: $oldestdate"
}

Everything seems to work up to the actual updating of the dates. That throws me this error:

Unable to find type ["Modified"]: make sure that the assembly containing this t
ype is loaded.
At <removed for privacy reasons>\update_dates.ps1:48 char:20
+     $item.["Modified"] <<<<  = $oldestdate;
    + CategoryInfo          : InvalidOperation: ("Modified":String) [], Runtim
   eException
    + FullyQualifiedErrorId : TypeNotFound

Item + <removed for privacy reasons> +  Org:  + 7/01/2012 16:37:18 +
New:  + 26/11/2010 22:33:56
Unable to find type ["Created"]: make sure that the assembly containing this ty
pe is loaded.
At <removed for privacy reasons>\update_dates.ps1:47 char:19
+     $item.["Created"] <<<<  = $oldestdate;
    + CategoryInfo          : InvalidOperation: ("Created":String) [], Runtime
   Exception
    + FullyQualifiedErrorId : TypeNotFound

Can anyone point me in the right direction?

share|improve this question
add comment

1 Answer

up vote 4 down vote accepted

Remove the . before [ in both lines

share|improve this answer
    
Oh. My. God. Thank you so much! :) It was right in front of me this entire time... –  Michael Davids May 29 '12 at 11:35
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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