0

I still have this problem with Sharepoint 2010 and Windows 7, i.e. Excel or Word documents edited from within Sharepoint display an outdated Date modified in Windows Explorer view. However, the 'Date last saved' is correct.

Hence, would it be possible to align the document's 'Date modified' with its 'Date last saved", perhaps with a Powershell script? The script would fix the dates of all documents of a folder (and optionally subfolders).

1
  • My organization applied the SharePoint Service Pack 2 recently and the initial problem was fixed, i.e. Date modified and Date last saved are now consistent. – gerdami Jan 8 '15 at 16:06
0

Here you go:

Function Do-WhatOPAskedFor
{
    param
    (
        [Microsoft.SharePoint.SPList] $list
    )

    # Please note that this is a bad way of getting all items from the list!
    $items = $list.Items
    $items | Align-DateFields "Modified" "Date Last Saved"
}

Function Align-DateFields
{
    param
    (       
        [string] $dateModifiedFieldName,
        [string] $dateLastSavedFieldName,
        [Parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true)]
        [Microsoft.SharePoint.SPListItem] $item
    )

    begin {}
    process
    {
        [DateTime]$dateLastSaved = $item[$dateLastSavedFieldName];
        $item[$dateModifiedFieldName] = $dateLastSaved;
        $item.Update();
    }
    end {}
}

Do-WhatOPAskedFor will do what you asked for; I'm just bad at naming functions. What it does is takes a SharePoint list, enumerates its items, and sends each item to be processed by a function. The function Align-DateFields takes a SharePoint list item, extracts what's in the specified field, and saves it to another field.

Let me know if you need any further details!

EDIT:

Here's some code to load up the SharePoint list and pass it to the function above:

# Do this if you can load the SharePoint module (e.g., are in a SharePoint Management Shell)
$web = Get-SPWeb http://yourwebsitehere;
$list = $web.Lists["Your list title here"];
Do-WhatOPAskedFor $list;
$web.Dispose();

# Do this if you only have a regular PowerShell shell:
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint") | Out-Null;
$site = New-Object Microsoft.SharePoint.SPSite("http://yoursitecollectionhere");
$web = $site.AllWebs | Where { $_.Title -eq "Your site title here" } | Select -First 1
$list = $web.Lists["Your list title here"];
Do-WhatOPAskedFor $list;
$site.Dispose();

In the first one, we use the functions in the SharePoint PowerShell module to grab the SPWeb, extract the SPList and pass it to the function. In the second, we have to load the Microsoft.SharePoint assembly, instantiate an SPSite object which contains the SPWeb, grab the SPWeb, extract the SPList, and pass it to the function.

2
  • Thanks. But, how I do I invoke the Do-WhatOPAskedFor function? – gerdami Oct 16 '14 at 6:04
  • If available, you can use the SharePoint Management Shell. If not, you can load up Microsoft.SharePoint as an assembly into a PowerShell shell. Then, copy and paste those functions, get a reference to the SharePoint list, and run it like any other PowerShell function – Jeff Freeman Oct 16 '14 at 15:43

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.