Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $Web = Get-SPWeb http://yoursite/
- $libName = "LibraryName"
- $lib = $Web.Lists |? {$_.Title -eq $libName}
- foreach ($item in $lib.Items)
- {
- $File = $item.File
- if( $File.CheckOutStatus -ne "None" -And $File.Versions.Count -eq 0)
- {
- $File.CheckIn("CheckIn")
- Write-Host "$($File.Name) has been Checked In" -ForeGroundColor yellow
- }
- }
- $Web.Dispose()
- #Force check-in of all documents
- $webUrl = "https://sharepoint/SiteCollection"
- $libraryTitle = "Shared Documents"
- Try
- {
- $web = Get-SPWeb $webUrl
- if($web -ne $null)
- {
- ForEach($list in ($web.Lists | ? {$_ -is [Microsoft.SharePoint.SPDocumentLibrary]}))
- {
- If($list.Title -eq $libraryTitle)
- {
- Write-Host "Evalating documents in " $list.Title
- # first get checked out files
- $fileIds = @()
- $Kount = 0
- Write-Host " Checking for files without a checked in version"
- ForEach($file in $list.CheckedOutFiles)
- {
- write-Host $file.LeafName
- $file.TakeOverCheckOut() # to retrieve item i have to do this before
- $doc = $list.getItemById($file.ListitemId)
- $itemFile = $doc.File
- if($itemFile -ne $null){
- $itemFile.CheckIn("Checked In By Administrator for achive")
- write-Host " Checked In" -ForeGroundColor Green
- }
- $Kount ++
- }
- Write-Host " Found $Kount files that have no checked in version"
- Write-Host " Evaluating files with checked in versions"
- ForEach($item in $list.Items)
- {
- Write-Host " " $item.Folder "" $item.File.Name
- if($item.File.CheckOutStatus -ne "None")
- {
- try
- {
- $fileName = $item.File.Name
- $userName = $item.File.CheckedOutByUser.Name;
- Write-Host "Document $fileName is checked out by $userName" -f
- $item.File.CheckIn("CheckIn by Administrator")
- }
- catch
- {
- Write-Host "Unable to check-in " $item.Url -ForegroundColor Red
- }
- }
- }
- $list.Update()
- }
- }
- }
- }
- Catch
- {
- Write-Host ($Error[0].Exception)
- }
Add Comment
Please, Sign In to add comment