How to Show Version History in SharePoint 2013 using PowerShell

How to Show Version History in SharePoint 2013 using PowerShell

Hello SharePoint Pals,
 
Here is an Interesting piece of requirement  that I would like to share with you all.  Suddenly one of my customers had come up with a requirement , that he would like to know how frequent the SharePoint doucment library is modified and usage analytics of the documents in a document library. The simple and efficient method that I follow is to get Version History for all the documents in a SharePoint Library using PowerShell Commands.
 
Here is the piece of code provided below.
 
  1. $Site = Get-SPSite http://mysite/Sample  
  2.   
  3. $Webs = $Site.AllWebs  
  4.   
  5. foreach ($Web in $Webs)  
  6. {  
  7. foreach ($List in $web.Lists)  
  8. {  
  9. //Check if the Versioning is enabled or not.  
  10.   
  11. if($List.EnableVersioning)  
  12. {  
  13. $Item=$List.Items[0]  
  14. foreach($Version in $Item.Versions)  
  15. {  
  16. Write-Host "Documen Library Name:" $List.Title "-" "Document Name:" $Item.Title $Version.VersionLabel  
  17. }  
  18. }  
  19. }  
  20. }  
  21. $Web.Dispose()  
  22. $Site.Dispose()  
Happy SharePointing :-)