Recently we got a problem that when the migration team is migrating the data from the older versions of the SharePoint to latest .
When migration is completed then forgot to check-in the files. So to check-in the files which have no minor checked-in versions.
Below script will check-in the files in the Document library.
cls
Remove-PSSnapin Microsoft.SharePoint.Powershell -ErrorAction SilentlyContinue
Add-PSSnapin Microsoft.SharePoint.Powershell
$rand = new-object System.Random
function CheckInDocument([string]$url)
{
$spWeb = Get-SPWeb $url
$SPBaseTypeDocumentLibrary = [Microsoft.SharePoint.SPBaseType]::DocumentLibrary
$lists = $spWeb.GetListsOfType($SPBaseTypeDocumentLibrary);
foreach ($list in $lists)
{
write-host $list.Title "&" $list.BaseTemplate.ToString()
if ($list.Hidden -eq $False -and $list.BaseTemplate.ToString() -eq "DocumentLibrary" -and $list.Title -eq "<<Document library Name>>")
{
Write-Host Checking in documents from Library : $list.Title
$getFolder = $spWeb.GetFolder($list.Title)
$files = $list.CheckedOutFiles
write-host "Total Checked Out Files : " $files.Count
$list.CheckedOutFiles | Where { $_.CheckOutStatus -ne "None" } |
ForEach {
$_.TakeOverCheckOut();
$docItem = $list.GetItemById($_.ListItemId);
#$docItem["test"] = "Some value";
$docItem.SystemUpdate();
$docItem.File.CheckIn("Since Migration team is not Checked In By Administrator");
Write-Host "$($docItem.File.Name) Checked In" -ForeGroundColor Green
}
}
}
$spWeb.Dispose()
}
CheckInDocument <<SiteURL>>
When migration is completed then forgot to check-in the files. So to check-in the files which have no minor checked-in versions.
Below script will check-in the files in the Document library.
cls
Remove-PSSnapin Microsoft.SharePoint.Powershell -ErrorAction SilentlyContinue
Add-PSSnapin Microsoft.SharePoint.Powershell
$rand = new-object System.Random
function CheckInDocument([string]$url)
{
$spWeb = Get-SPWeb $url
$SPBaseTypeDocumentLibrary = [Microsoft.SharePoint.SPBaseType]::DocumentLibrary
$lists = $spWeb.GetListsOfType($SPBaseTypeDocumentLibrary);
foreach ($list in $lists)
{
write-host $list.Title "&" $list.BaseTemplate.ToString()
if ($list.Hidden -eq $False -and $list.BaseTemplate.ToString() -eq "DocumentLibrary" -and $list.Title -eq "<<Document library Name>>")
{
Write-Host Checking in documents from Library : $list.Title
$getFolder = $spWeb.GetFolder($list.Title)
$files = $list.CheckedOutFiles
write-host "Total Checked Out Files : " $files.Count
$list.CheckedOutFiles | Where { $_.CheckOutStatus -ne "None" } |
ForEach {
$_.TakeOverCheckOut();
$docItem = $list.GetItemById($_.ListItemId);
#$docItem["test"] = "Some value";
$docItem.SystemUpdate();
$docItem.File.CheckIn("Since Migration team is not Checked In By Administrator");
Write-Host "$($docItem.File.Name) Checked In" -ForeGroundColor Green
}
}
}
$spWeb.Dispose()
}
CheckInDocument <<SiteURL>>
No comments:
Post a Comment