{"id":540,"date":"2025-12-18T10:13:55","date_gmt":"2025-12-18T07:13:55","guid":{"rendered":"https:\/\/kb.astrocroc.com\/?p=540"},"modified":"2025-12-18T10:13:55","modified_gmt":"2025-12-18T07:13:55","slug":"%d0%ba%d0%b0%d0%ba-%d0%be%d1%82%d0%bc%d0%b5%d0%bd%d0%b8%d1%82%d1%8c-%d0%b8%d0%b7%d0%bb%d0%b5%d1%87%d0%b5%d0%bd%d0%b8%d0%b5-%d1%84%d0%b0%d0%b9%d0%bb%d0%b0-%d0%b2-%d0%b1%d0%b8%d0%b1%d0%bb%d0%b8%d0%be","status":"publish","type":"post","link":"https:\/\/kb.astrocroc.com\/?p=540","title":{"rendered":"\u041a\u0430\u043a \u043e\u0442\u043c\u0435\u043d\u0438\u0442\u044c \u0438\u0437\u043b\u0435\u0447\u0435\u043d\u0438\u0435 \u0444\u0430\u0439\u043b\u0430 \u0432 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0435 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e powershell \u0441\u043a\u0440\u0438\u043f\u0442\u0430"},"content":{"rendered":"\n<pre class=\"wp-block-prismatic-blocks\"><code class=\"language-powershell\" data-line=\"\">Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue\n\n# ===== \u041d\u0410\u0421\u0422\u0420\u041e\u0419\u041a\u0418 =====\n$siteUrl     = &quot;http:\/\/sp2013\/sites\/YourSite&quot;   # URL \u0441\u0430\u0439\u0442\u0430\n$libraryName = &quot;\u0414\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u044b&quot;                      # \u0418\u043c\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 (\u043a\u0430\u043a \u0432 URL\/\u043d\u0430 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0435)\n$fileName    = &quot;FileName.docx&quot;                  # \u0418\u043c\u044f \u0444\u0430\u0439\u043b\u0430 (\u0431\u0435\u0437 \u043f\u0443\u0442\u0438 \u043a \u043f\u0430\u043f\u043a\u0435)\n#$folderRel   = &quot;SubFolder1\/SubFolder2&quot;         # \u041e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u043f\u0443\u0442\u044c \u043a \u043f\u0430\u043f\u043a\u0435 \u0432\u043d\u0443\u0442\u0440\u0438 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 (\u0435\u0441\u043b\u0438 \u043d\u0443\u0436\u043d\u043e)\n\n# ===== \u041b\u041e\u0413\u0418\u041a\u0410 =====\n$web = Get-SPWeb $siteUrl\n\ntry {\n    # \u041f\u0430\u043f\u043a\u0430 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438\n    $folder = $web.GetFolder($libraryName)\n    if (-not $folder.Exists) {\n        Write-Host &quot;\u041f\u0430\u043f\u043a\u0430 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 &#039;$libraryName&#039; \u043d\u0435 \u043d\u0430\u0439\u0434\u0435\u043d\u0430&quot; -ForegroundColor Red\n        return\n    }\n\n    # \u0415\u0441\u043b\u0438 \u043d\u0443\u0436\u0435\u043d \u043f\u043e\u0438\u0441\u043a \u0432\u043d\u0443\u0442\u0440\u0438 \u043f\u043e\u0434\u043f\u0430\u043f\u043e\u043a \u2013 \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0439\u0442\u0438\u0441\u044c \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u043e, \u043d\u043e \u0437\u0434\u0435\u0441\u044c \u0431\u0435\u0440\u0451\u043c \u0442\u043e\u043b\u044c\u043a\u043e \u043a\u043e\u0440\u0435\u043d\u044c \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438\n    $file = $folder.Files | Where-Object { $_.Name -eq $fileName }\n\n    if ($file -eq $null) {\n        Write-Host &quot;\u0424\u0430\u0439\u043b &#039;$fileName&#039; \u043d\u0435 \u043d\u0430\u0439\u0434\u0435\u043d \u0432 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0435 &#039;$libraryName&#039; (\u043a\u043e\u0440\u043d\u0435\u0432\u0430\u044f \u043f\u0430\u043f\u043a\u0430)&quot; -ForegroundColor Yellow\n        return\n    }\n\n    if ($file.CheckOutStatus -ne &quot;None&quot;) {\n        Write-Host &quot;\u0424\u0430\u0439\u043b \u0438\u0437\u0432\u043b\u0435\u0447\u0451\u043d. \u0412\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f UndoCheckOut()...&quot; -ForegroundColor Cyan\n        $file.UndoCheckOut()\n        $file.Update()\n        Write-Host &quot;\u0418\u0437\u0432\u043b\u0435\u0447\u0435\u043d\u0438\u0435 \u043e\u0442\u043c\u0435\u043d\u0435\u043d\u043e \u0434\u043b\u044f \u0444\u0430\u0439\u043b\u0430: $($file.Url)&quot; -ForegroundColor Green\n    } else {\n        Write-Host &quot;\u0424\u0430\u0439\u043b &#039;$fileName&#039; \u043d\u0435 \u0438\u0437\u0432\u043b\u0435\u0447\u0451\u043d (CheckOutStatus = None)&quot; -ForegroundColor Yellow\n    }\n}\nfinally {\n    if ($web -ne $null) { $web.Dispose() }\n}\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"url\">\u0412\u0430\u0440\u0438\u0430\u043d\u0442 \u043f\u043e URL \u0444\u0430\u0439\u043b\u0430<\/h2>\n\n\n\n<p>\u0415\u0441\u043b\u0438 \u0443\u0434\u043e\u0431\u043d\u0435\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 <strong>\u043f\u043e\u043b\u043d\u044b\u043c \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u043c URL \u0444\u0430\u0439\u043b\u0430<\/strong>, \u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0442\u0430\u043a:<a rel=\"noreferrer noopener\" target=\"_blank\" href=\"https:\/\/pholpar.wordpress.com\/2014\/04\/03\/how-to-use-powershell-to-delete-short-term-locks-from-documents-opened-from-sharepoint\/\"><\/a><\/p>\n\n\n\n<pre class=\"wp-block-prismatic-blocks\"><code class=\"language-powershell\" data-line=\"\">Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue\n\n$siteUrl  = &quot;http:\/\/sp2013\/sites\/YourSite&quot;\n$fileUrl  = &quot;\/sites\/YourSite\/\u0414\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u044b\/Folder1\/FileName.docx&quot;  # server-relative URL \u0444\u0430\u0439\u043b\u0430\n\n$web = Get-SPWeb $siteUrl\n\ntry {\n    $file = $web.GetFile($fileUrl)\n\n    if (-not $file.Exists) {\n        Write-Host &quot;\u0424\u0430\u0439\u043b \u043f\u043e URL &#039;$fileUrl&#039; \u043d\u0435 \u043d\u0430\u0439\u0434\u0435\u043d&quot; -ForegroundColor Red\n        return\n    }\n\n    if ($file.CheckOutStatus -ne &quot;None&quot;) {\n        Write-Host &quot;\u0424\u0430\u0439\u043b \u0438\u0437\u0432\u043b\u0435\u0447\u0451\u043d \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u043c $($file.CheckedOutByUser)&quot; -ForegroundColor Cyan\n        $file.UndoCheckOut()\n        $file.Update()\n        Write-Host &quot;\u0418\u0437\u0432\u043b\u0435\u0447\u0435\u043d\u0438\u0435 \u043e\u0442\u043c\u0435\u043d\u0435\u043d\u043e \u0434\u043b\u044f \u0444\u0430\u0439\u043b\u0430: $fileUrl&quot; -ForegroundColor Green\n    } else {\n        Write-Host &quot;\u0424\u0430\u0439\u043b \u043d\u0435 \u0438\u0437\u0432\u043b\u0435\u0447\u0451\u043d (CheckOutStatus = None)&quot; -ForegroundColor Yellow\n    }\n}\nfinally {\n    if ($web -ne $null) { $web.Dispose() }\n}\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u0412\u0430\u0440\u0438\u0430\u043d\u0442 \u043f\u043e URL \u0444\u0430\u0439\u043b\u0430 \u0415\u0441\u043b\u0438 \u0443\u0434\u043e\u0431\u043d\u0435\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u043f\u043e\u043b\u043d\u044b\u043c \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u043c URL \u0444\u0430\u0439\u043b\u0430, \u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0442\u0430\u043a:<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11],"tags":[49],"class_list":["post-540","post","type-post","status-publish","format-standard","hentry","category-sharepoint","tag-powershell"],"blocksy_meta":[],"_links":{"self":[{"href":"https:\/\/kb.astrocroc.com\/index.php?rest_route=\/wp\/v2\/posts\/540","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kb.astrocroc.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kb.astrocroc.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kb.astrocroc.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kb.astrocroc.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=540"}],"version-history":[{"count":1,"href":"https:\/\/kb.astrocroc.com\/index.php?rest_route=\/wp\/v2\/posts\/540\/revisions"}],"predecessor-version":[{"id":541,"href":"https:\/\/kb.astrocroc.com\/index.php?rest_route=\/wp\/v2\/posts\/540\/revisions\/541"}],"wp:attachment":[{"href":"https:\/\/kb.astrocroc.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=540"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kb.astrocroc.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=540"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kb.astrocroc.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=540"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}