0

The following PowerShell script pulls all the content from a specified SharePoint site and creates an audit log for all versions and dates. My Question is how would I implement a Start/End date? For example I would like to view only the items between 10/3/2014 and 10/5/2014.

$web = Get-SPWeb http://<SharePoint Site>
ForEach($list in $web.Lists) 
{
 ForEach($item in $list.Items)
 { 
  ForEach($version in $item.Versions)
  {    
    $fullURL = "$($web.URL)$($list.URL)/$($version.URL)"    
    "{0}`t{1}`t{2}`t{3}`t{4}" -f $fullURL, $version.VersionLabel, $version.CreatedBy.User.UserLogin, $version.Created, $list.BaseType  | out-file Versions.csv -Append  
  }   
 } 
} 

1 Answer 1

0

Try this

$web = Get-SPWeb http://devintranet.tokiomillennium.com/operations/claims
$startDate = [datetime]::ParseExact("10/03/14", "dd/MM/yy", $null)
$endDate = [datetime]::ParseExact("10/05/14", "dd/MM/yy", $null)

ForEach($list in $web.Lists) 
{
    ForEach($item in $list.Items)
    { 
        ForEach($version in $item.Versions)
        {    
            if($version.Created -ge $startDate -AND $version.Created -le $endDate)
            {
                $fullURL = "$($web.URL)$($list.URL)/$($version.URL)"        
                "{0}`t{1}`t{2}`t{3}`t{4}" -f $fullURL, $version.VersionLabel, $version.CreatedBy.User.UserLogin, $version.Created, $list.BaseType  | out-file Versions.csv -Append  
            }
        }   
    } 
}
1
  • Amal, thanks for the response. When I test it out I get the following error: Exception calling "ParseExact" with "3" argument(s): "The DateTime represented by the string is not supported in calendar System.Globalization.GregorianCalendar." Nov 21, 2014 at 12:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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