Guest User

Untitled

a guest
Jun 18th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.33 KB | None | 0 0
  1. $Web = Get-SPWeb http://yoursite/
  2. $libName = "LibraryName"
  3. $lib = $Web.Lists |? {$_.Title -eq $libName}
  4. foreach ($item in $lib.Items)
  5. {
  6. $File = $item.File
  7. if( $File.CheckOutStatus -ne "None" -And $File.Versions.Count -eq 0)
  8. {
  9. $File.CheckIn("CheckIn")
  10. Write-Host "$($File.Name) has been Checked In" -ForeGroundColor yellow
  11. }
  12. }
  13. $Web.Dispose()
  14.  
  15. #Force check-in of all documents
  16. $webUrl = "https://sharepoint/SiteCollection"
  17. $libraryTitle = "Shared Documents"
  18.  
  19. Try
  20. {
  21. $web = Get-SPWeb $webUrl
  22. if($web -ne $null)
  23. {
  24.  
  25. ForEach($list in ($web.Lists | ? {$_ -is [Microsoft.SharePoint.SPDocumentLibrary]}))
  26. {
  27.  
  28. If($list.Title -eq $libraryTitle)
  29. {
  30. Write-Host "Evalating documents in " $list.Title
  31. # first get checked out files
  32.  
  33. $fileIds = @()
  34. $Kount = 0
  35. Write-Host " Checking for files without a checked in version"
  36. ForEach($file in $list.CheckedOutFiles)
  37. {
  38. write-Host $file.LeafName
  39. $file.TakeOverCheckOut() # to retrieve item i have to do this before
  40. $doc = $list.getItemById($file.ListitemId)
  41. $itemFile = $doc.File
  42. if($itemFile -ne $null){
  43. $itemFile.CheckIn("Checked In By Administrator for achive")
  44. write-Host " Checked In" -ForeGroundColor Green
  45. }
  46. $Kount ++
  47. }
  48. Write-Host " Found $Kount files that have no checked in version"
  49. Write-Host " Evaluating files with checked in versions"
  50.  
  51. ForEach($item in $list.Items)
  52. {
  53. Write-Host " " $item.Folder "" $item.File.Name
  54. if($item.File.CheckOutStatus -ne "None")
  55. {
  56. try
  57. {
  58. $fileName = $item.File.Name
  59. $userName = $item.File.CheckedOutByUser.Name;
  60. Write-Host "Document $fileName is checked out by $userName" -f
  61. $item.File.CheckIn("CheckIn by Administrator")
  62. }
  63. catch
  64. {
  65. Write-Host "Unable to check-in " $item.Url -ForegroundColor Red
  66. }
  67. }
  68. }
  69. $list.Update()
  70. }
  71. }
  72. }
  73. }
  74. Catch
  75. {
  76. Write-Host ($Error[0].Exception)
  77. }
Add Comment
Please, Sign In to add comment