{"id":356,"date":"2015-06-05T08:23:54","date_gmt":"2015-06-05T13:23:54","guid":{"rendered":"http:\/\/nukeitmike.com\/blog\/?p=356"},"modified":"2015-06-05T08:23:54","modified_gmt":"2015-06-05T13:23:54","slug":"sharepoint-documents-are-all-checked-out","status":"publish","type":"post","link":"https:\/\/blog.nukeitmike.com\/index.php\/2015\/06\/05\/sharepoint-documents-are-all-checked-out\/","title":{"rendered":"SharePoint Documents are all checked out"},"content":{"rendered":"<p>I wanted to write a PowerShell script to check all the documents back in that had been checked out.&#160; Turns out that is not as straight forward as I had hoped.<\/p>\n<p>First search came up with this: <a title=\"Office Discarding Check Out Using PowerShell\" href=\"https:\/\/gallery.technet.microsoft.com\/office\/Discarding-Check-Out-Using-72115caa\" target=\"_blank\" rel=\"noopener\">Office Discarding Check Out Using PowerShell<\/a><\/p>\n<p>Then when I tried to run the command (from the server console, because it doesn\u2019t appear that you can just install the SP PowerShell Module on your desktop), I received the error below:<\/p>\n<blockquote>\n<p>Get-SPWeb : Cannot access the local farm. Verify that the local farm is properly configured, currently available, and that you have the appropriate permissions to access the database before trying again.<\/p>\n<\/blockquote>\n<p>That let me to this site: <a title=\"http:\/\/www.sharepointassist.com\/2010\/01\/29\/the-local-farm-is-not-accessible-cmdlets-with-featuredependencyid-are-not-registered\/comment-page-1\/#comment-1566\" href=\"http:\/\/www.sharepointassist.com\/2010\/01\/29\/the-local-farm-is-not-accessible-cmdlets-with-featuredependencyid-are-not-registered\/comment-page-1\/#comment-1566\">http:\/\/www.sharepointassist.com\/2010\/01\/29\/the-local-farm-is-not-accessible-cmdlets-with-featuredependencyid-are-not-registered\/comment-page-1\/#comment-1566<\/a><\/p>\n<p>and this answer:<\/p>\n<blockquote>\n<p>run sharepoint management shell with the service account     <br \/>$db = Get-SPDatabase | Where {$_.Name -eq \u201cSharePoint_ConfigDB\u201d}      <br \/>Add-SPShellAdmin \u201cdomain\\user_to_add\u201d -database $db<\/p>\n<\/blockquote>\n<p>So I looked figured out how to accomplish that and moved on to writing the script for checking in files.&#160; I ran out of time to work on this.&#160; It will accomplish the task, but it isn\u2019t as clean and efficient as I would like.<\/p>\n<blockquote>\n<p># Put your site root here     <br \/>$TargetSite = &quot;https:\/\/your.site.name\/blah\/blah\/blah&quot;       <br \/># The root folder that you want to start with      <br \/>$TargetLibrary = &quot;Shared Documents&quot; <\/p>\n<p>&#160;<\/p>\n<p>function LookForWorkFiles ($workFolder){     <br \/>&#160;&#160;&#160; Write-Host $workFolder      <br \/>&#160;&#160;&#160; # Get the SubFolder and work through it      <br \/>&#160;&#160;&#160; $wf = $Site.GetFolder($workFolder)      <br \/>&#160;&#160;&#160; # Get the files      <br \/>&#160;&#160;&#160; $FilesToProcess = $wf.Files      <br \/>&#160;&#160;&#160; <br \/>&#160;&#160;&#160; Write-Host &quot;How many files you ask?&quot;      <br \/>&#160;&#160;&#160; Write-Host $FilesToProcess.Count      <br \/>&#160;&#160;&#160; If ($FilesToProcess.Count -le 0) {      <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; # If there aren&#8217;t any files, move on to the SubFolders      <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; Write-Host &quot;No Files in $workFolder, checking for subfolders&quot;      <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; }      <br \/>&#160;&#160;&#160; Else       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; {      <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; # Check in all the files -NOTE this will cause an error for any       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; # file that isn&#8217;t checked out.&#160; <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; foreach ($_ in $FilesToProcess) {      <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Write-Host $_.Name      <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; $_.UndoCheckOut()      <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; $_.Update()      <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }      <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; }      <br \/>&#160;&#160;&#160; Write-Host &quot;Looking for Subfolders&quot;      <br \/>&#160;&#160;&#160; Write-Host $wf.SubFolders      <br \/>&#160;&#160;&#160; foreach ($_ in $wf.SubFolders){      <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; Write-Host &quot;SubFolders?&quot;      <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; $Site.GetFolder($_)      <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; LookForWorkFiles $_      <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; }      <br \/>&#160;&#160;&#160; }      <br \/>&#160;&#160;&#160; <br \/>&#160;&#160;&#160; <br \/>Write-Host &quot;Beginning Script&quot;      <br \/>Write-Host $TargetSite      <br \/>Write-Host $TargetLibrary<\/p>\n<p>#Connect to the site     <br \/>$Site = Get-SPWeb $TargetSite       <br \/>#Get the Document Folder      <br \/>$Folder = $Site.GetFolder($TargetLibrary) <\/p>\n<p>foreach ($SPF in $Folder.SubFolders ){      <br \/>&#160;&#160;&#160; If ($SPF.Name -eq &quot;Forms&quot;){      <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; #the forms directory is for SharePoint, not for file management      <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; Write-Host &quot;Skipping the Forms Directory&quot;      <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; }      <br \/>&#160;&#160;&#160; Else      <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; {      <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; Write-Host $SPF.Name      <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; LookForWorkFiles $SPF      <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; }      <br \/>&#160;&#160;&#160; }<\/p>\n<\/blockquote>\n<p>With this script, it is easier to use file management tools to move the files out of SharePoint.&#160; <\/p>\n","protected":false},"excerpt":{"rendered":"<p>I wanted to write a PowerShell script to check all the documents back in that had been checked out.&#160; Turns out that is not as straight forward as I had hoped. First search came up with this: Office Discarding Check Out Using PowerShell Then when I tried to run the command (from the server console,&hellip; <a class=\"more-link\" href=\"https:\/\/blog.nukeitmike.com\/index.php\/2015\/06\/05\/sharepoint-documents-are-all-checked-out\/\">Continue reading <span class=\"screen-reader-text\">SharePoint Documents are all checked out<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"advanced_seo_description":"","jetpack_seo_html_title":"","jetpack_seo_noindex":false,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[17,25,29],"tags":[78,89,120,135,154,162],"class_list":["post-356","post","type-post","status-publish","format-standard","hentry","category-microsoft","category-scripting","category-sharepoint","tag-document-library","tag-file-management","tag-microsoft","tag-powershell","tag-scripting","tag-sharepoint","entry"],"jetpack_featured_media_url":"","jetpack-related-posts":[],"jetpack_likes_enabled":true,"jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/pcW544-5K","_links":{"self":[{"href":"https:\/\/blog.nukeitmike.com\/index.php\/wp-json\/wp\/v2\/posts\/356","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.nukeitmike.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.nukeitmike.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.nukeitmike.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.nukeitmike.com\/index.php\/wp-json\/wp\/v2\/comments?post=356"}],"version-history":[{"count":0,"href":"https:\/\/blog.nukeitmike.com\/index.php\/wp-json\/wp\/v2\/posts\/356\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.nukeitmike.com\/index.php\/wp-json\/wp\/v2\/media?parent=356"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.nukeitmike.com\/index.php\/wp-json\/wp\/v2\/categories?post=356"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.nukeitmike.com\/index.php\/wp-json\/wp\/v2\/tags?post=356"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}