0

I want to get items from a document library where File Size=1KB and it has certain document version 2.0 below script.I created but how can I enhance it?

$web = Get-SPWeb -Identity http://application url
$list = $web.Lists["CsFarms"]
$items = $list.Items
foreach ($item in $items) | where {$_['File Size'] -eq 1KB}
{
    $file = $item.File
    $fileVersions = $file.Versions      
    if ($fileVersions = 2.0)
    {           


    }   
}

my requirement is i want to check for if any document has more than two versions i want restore from its version number 2.0

enter image description here

  • Is this script working? – akbar ali Jan 16 '17 at 7:54
  • no please check the image i want to restore every document that has v2.0 and some documents i want to skip that has only one version and size of documents is more than 1 KB – adilahmed Jan 16 '17 at 9:15
2

Try this script, you can use the $xml.row.ows_FileSizeDisplay to check file size.

$web = Get-SPWeb -Identity http://application url
$list = $web.Lists["CsFarms"]
$items = $list.Items

foreach ($item in $items)
{
    $file = $item.File
    $fileVersions = $file.Versions   
    $xml = [xml]$item.xml
       $filesize = $xml.row.ows_FileSizeDisplay
    if ($fileVersions.Count -gt 1 -and (([int]$filesize)/1024) -eq 1)
    {           
           $fileVersions.RestoreByLabel(2.0) 
    }   
}
  • hi i want to check file size=1kb – adilahmed Jan 16 '17 at 8:14
  • 1
    @adilahmed, just switch -gt to -eq 1. – Christoffer Jan 16 '17 at 8:24
  • hi my requirement is i want to check for if any document has more than two versions i want restore from its version number 2.0 – adilahmed Jan 16 '17 at 8:38
  • $fileVersions it returns all documents and i can not able to restore version number 2.0 $fileVersions.Restore(2.0) – adilahmed Jan 16 '17 at 9:00
  • try this $fileVersions.RestoreByLabel(2.0) – akbar ali Jan 16 '17 at 11:36

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.