SharePoint 2010 Powershell

Christopher Gore
Christopher Gore used Ask the Experts™
on
Do one of you SharePoint 2010 gurus have the Powershell script to check in or undo-checkout of all item's in a picture library.  If you used SP2010 you are probably failure with when you check them in sometimes they still show checked-out.  I know there is a -force way to do it.  I just cannot remember it.  

Goal: Loop through all the documents in a specific Picture Library in a particular site and check them all in (or undo checkout)
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Cloud Expert
Most Valuable Expert 2013
Top Expert 2014
Commented:
Tested this and it works;

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
 
#Variables for Site URL and Library Name
$WebURL="http://YourURL/YourSite"
$LibraryName="YourPictureLib"
 
#Get Site and Library
$Web = Get-SPWeb $WebURL
$DocLib = $Web.Lists.TryGetList($LibraryName)
 
#Get all Checked out files
$CheckedOutFiles = $DocLib.Items | Where-Object { $_.File.CheckOutStatus -ne "None"}
 
#Check in All Checked out Files in the library
ForEach($item in $CheckedOutFiles)
    {

        $DocLib.GetItemById($item.Id).file.CheckIn("Checked in by Admin")
        write-host "File:'$($item.Name)' has been checked in!"        
    }

Open in new window

Christopher GoreEnterprise Solutions Architect

Author

Commented:
Sorry.  That did not fix it.  They still show up as checked out to me.
Kamlesh RaoIT Consultant

Commented:
Hey Christopher, your comment says that the script didn't help.  At the same time you have accepted it as the solution!!!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial