{"id":2458,"date":"2025-11-24T14:46:54","date_gmt":"2025-11-24T14:46:54","guid":{"rendered":"https:\/\/www.mainmind.com\/blog\/?p=2458"},"modified":"2026-04-16T16:37:00","modified_gmt":"2026-04-16T16:37:00","slug":"desbloquear-archivos-en-red","status":"publish","type":"post","link":"https:\/\/www.mainmind.com\/blog\/desbloquear-archivos-en-red\/","title":{"rendered":"Desbloquear archivos en red"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">En ocasiones el cambio o aplicaci\u00f3n de pol\u00edticas de red en carpetas compartidas puede llegar a dejar sin permisos documentos que anteriormente si eran accesible, sobre todo en vista previa. Este comportamiento en cuanto a seguridad y actualizaciones de Microsoft en entornos de empresa son necesario revisarlos&#8230; pero si al final tenemos que desbloquear ficheros de manera recursiva&#8230; vamos a echar mano de alg\u00fan script en powershell&#8230;<\/p>\n\n\n\n<!--more-->\n\n\n\n<p class=\"wp-block-paragraph\">Se pueden a\u00f1adir m\u00e1s extensiones, pero se utiliza para PDF, Word y Excel&#8230;<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: powershell; title: ; notranslate\" title=\"\">\n&lt;#\nEste script est\u00e1 disponible bajo la licencia MIT.\nCopyright (c) 2025 Kaizen Development Solutions.\n\nSe permite el uso, copia, modificaci\u00f3n y distribuci\u00f3n del software\nsiempre que se mantenga este aviso de copyright y la referencia a la\nlicencia MIT. El software se proporciona &quot;tal cual&quot;, sin garant\u00edas de\nning\u00fan tipo. Para m\u00e1s detalles consulte el archivo LICENSE del\nrepositorio.\n\n.SYNOPSIS\nDesbloquea (quita el &quot;Unblock&quot;) a ficheros PDF, Word, Excel y PowerPoint.\nEn PowerShell 5 puede dar problemas con rutas largas\n\n.EXAMPLE\n.\\Desbloquear-Docs.ps1\n\nUsa el directorio actual, pide confirmaci\u00f3n y desbloquea los archivos.\n\n.EXAMPLE\n.\\Desbloquear-Docs.ps1 &quot;C:\\Carpeta\\Documentos&quot;\n\nProcesa esa ruta sin preguntar.\n#&gt;\n\nparam(\n    &#x5B;string]$Path\n)\n\nfunction Test-IsBlocked {\n    param(\n        &#x5B;Parameter(Mandatory)]\n        &#x5B;string]$FilePath\n    )\n\n    try {\n        # Si existe el stream Zone.Identifier, el archivo est\u00e1 bloqueado\n        $stream = Get-Item -LiteralPath $FilePath -Stream Zone.Identifier -ErrorAction SilentlyContinue\n        return ($null -ne $stream)\n    }\n    catch {\n        return $false\n    }\n}\n\n# Devuelve $true si la excepci\u00f3n es un &quot;sharing violation&quot; (archivo en uso)\nfunction Test-IsSharingViolation {\n    param(\n        &#x5B;Parameter(Mandatory)]\n        &#x5B;System.Exception]$Exception\n    )\n\n    # ERROR_SHARING_VIOLATION = 32 -&gt; HRESULT 0x80070020\n    if ($Exception -is &#x5B;System.IO.IOException]) {\n        $h = $Exception.HResult\n        if ($h -eq 0x80070020 -or (($h -band 0xFFFF) -eq 32)) {\n            return $true\n        }\n    }\n    return $false\n}\n\n# Variables globales para la funci\u00f3n recursiva\n$script:ok      = 0\n$script:skipped = 0\n$script:fail    = 0\n\nfunction Process-Directory {\n    param(\n        &#x5B;Parameter(Mandatory)]\n        &#x5B;string]$DirectoryPath\n    )\n\n    # Enumerar el directorio; si no hay permisos, registrar y salir\n    try {\n        $items = Get-ChildItem -LiteralPath $DirectoryPath -ErrorAction Stop\n    }\n    catch {\n        $msg = &quot;&#x5B;Enumeraci\u00f3n] Directorio: $DirectoryPath -&gt; $($_.Exception.Message)&quot;\n        Add-Content -Path $script:logPath -Value $msg\n        $script:fail++\n        return\n    }\n\n\t# Sin -recursive para evitar problemas de enumaracion y permisos\n    foreach ($item in $items) {\n        if ($item.PSIsContainer) {\n            Process-Directory -DirectoryPath $item.FullName\n        }\n        else {\n            $ext = $item.Extension.ToLower()\n\n            if ($script:validExts -contains $ext) {\n                $filePath = $item.FullName\n\n                if (Test-IsBlocked -FilePath $filePath) {\n                    try {\n                        Unblock-File -Path $filePath -ErrorAction Stop\n                        Write-Host &quot;&#x5B;OK]   $filePath&quot;\n                        $script:ok++\n                    }\n                    catch {\n                        $ex = $_.Exception\n                        if (Test-IsSharingViolation -Exception $ex) {\n                            $msg = &quot;&#x5B;IN USE]       $filePath -&gt; $($ex.Message)&quot;\n                        }\n                        else {\n                            $msg = &quot;&#x5B;Unblock-File] $filePath -&gt; $($ex.Message)&quot;\n                        }\n\n                        Write-Host $msg -ForegroundColor Yellow\n                        Add-Content -Path $script:logPath -Value $msg\n                        $script:fail++\n                    }\n                }\n                else {\n                    Write-Host &quot;&#x5B;SKIP] $filePath (no bloqueado)&quot; -ForegroundColor DarkGray\n                    $script:skipped++\n                }\n            }\n        }\n    }\n}\n\n# --- Par\u00e1metros y confirmaci\u00f3n ---\nif (-not $Path -or &#x5B;string]::IsNullOrWhiteSpace($Path)) {\n    $Path = (Get-Location).Path\n\n    $respuesta = Read-Host &quot;\u00bfDesea desbloquear los ficheros PDF, Word, Excel y PowerPoint contenidos en el directorio actual `&quot;$Path`&quot;? (S\/N)&quot;\n    if ($respuesta.ToUpper() -ne &#039;S&#039;) {\n        Write-Host &quot;Operaci\u00f3n cancelada.&quot;\n        exit 0\n    }\n}\n\n# Normalizar ruta\n$Path = (Resolve-Path -Path $Path).Path\n\nif (-not (Test-Path -Path $Path -PathType Container)) {\n    Write-Host &quot;Ruta no v\u00e1lida: $Path&quot; -ForegroundColor Red\n    exit 1\n}\n\nWrite-Host &quot;Procesando ficheros en: $Path&quot;\nWrite-Host &quot;&quot;\n\n# Extensiones v\u00e1lidas\n$script:validExts = @(\n    &#039;.pdf&#039;,\n    &#039;.doc&#039;,&#039;.docx&#039;,&#039;.docm&#039;,&#039;.dot&#039;,&#039;.dotx&#039;,\n    &#039;.xls&#039;,&#039;.xlsx&#039;,&#039;.xlsm&#039;,&#039;.xlsb&#039;,\n    &#039;.ppt&#039;,&#039;.pptx&#039;,&#039;.pptm&#039;\n)\n\n# Carpeta de logs en la unidad del PATH\n$driveRoot = &#x5B;System.IO.Path]::GetPathRoot($Path)      # Ej: &quot;E:\\&quot;\n$logFolder = Join-Path $driveRoot &quot;KDS\\logs&quot;\n\nNew-Item -ItemType Directory -Path $logFolder -Force | Out-Null\n\n$logName = &quot;UnblockErrors_{0:yyyyMMdd_HHmmss}.txt&quot; -f (Get-Date)\n$script:logPath = Join-Path $logFolder $logName\n\nNew-Item -Path $script:logPath -ItemType File -Force | Out-Null\n\nWrite-Host &quot;Log de errores: $script:logPath&quot;\nWrite-Host &quot;&quot;\n\n# Lanzar proceso\nProcess-Directory -DirectoryPath $Path\n\nWrite-Host &quot;&quot;\nWrite-Host &quot;Resumen:&quot;\nWrite-Host &quot;  Archivos desbloqueados : $($script:ok)&quot;\nWrite-Host &quot;  Archivos no bloqueados : $($script:skipped)&quot;\nWrite-Host &quot;  Errores registrados    : $($script:fail)&quot;\nWrite-Host &quot;&quot;\nWrite-Host &quot;Log en: $script:logPath&quot;\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\"><strong>Actualizado 2021\/11\/20<\/strong>: inicio <a href=\"https:\/\/github.com\/mainmind83\/PowerShell\">repositorio de scripts en Github<\/a><br>Descargar: <a href=\"https:\/\/github.com\/mainmind83\/PowerShell\/blob\/main\/Desbloquear-docs.ps1\">https:\/\/github.com\/mainmind83\/PowerShell\/blob\/main\/Desbloquear-docs.ps1<\/a><\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"405\" height=\"577\" src=\"https:\/\/www.mainmind.com\/blog\/wp-content\/uploads\/2025\/windows_unblock_file.jpg\" alt=\"windows_unblock_file sobre 2025\" class=\"wp-image-2468\" srcset=\"https:\/\/www.mainmind.com\/blog\/wp-content\/uploads\/2025\/windows_unblock_file.jpg 405w, https:\/\/www.mainmind.com\/blog\/wp-content\/uploads\/2025\/windows_unblock_file-211x300.jpg 211w\" sizes=\"auto, (max-width: 405px) 100vw, 405px\" \/><\/figure>\n<\/div>","protected":false},"excerpt":{"rendered":"<p>En ocasiones el cambio o aplicaci\u00f3n de pol\u00edticas de red en carpetas compartidas puede llegar a dejar sin permisos documentos que anteriormente si eran accesible, sobre todo en vista previa. Este comportamiento en cuanto a seguridad y actualizaciones de Microsoft en entornos de empresa son necesario revisarlos&#8230; pero si al final tenemos que desbloquear ficheros [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":2473,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[19],"tags":[123,1040,1041,1042],"class_list":["post-2458","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-seguridad","tag-powershell","tag-unlock","tag-zona","tag-zone"],"_links":{"self":[{"href":"https:\/\/www.mainmind.com\/blog\/wp-json\/wp\/v2\/posts\/2458","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.mainmind.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.mainmind.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.mainmind.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.mainmind.com\/blog\/wp-json\/wp\/v2\/comments?post=2458"}],"version-history":[{"count":6,"href":"https:\/\/www.mainmind.com\/blog\/wp-json\/wp\/v2\/posts\/2458\/revisions"}],"predecessor-version":[{"id":2472,"href":"https:\/\/www.mainmind.com\/blog\/wp-json\/wp\/v2\/posts\/2458\/revisions\/2472"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.mainmind.com\/blog\/wp-json\/wp\/v2\/media\/2473"}],"wp:attachment":[{"href":"https:\/\/www.mainmind.com\/blog\/wp-json\/wp\/v2\/media?parent=2458"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.mainmind.com\/blog\/wp-json\/wp\/v2\/categories?post=2458"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.mainmind.com\/blog\/wp-json\/wp\/v2\/tags?post=2458"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}