From 5c838384d6e226efd1be703849f083faab65c155 Mon Sep 17 00:00:00 2001 From: HetCreep Date: Sun, 9 Aug 2026 06:24:14 +0700 Subject: [PATCH] fix: remove Mark-of-the-Web from script files at startup (#724) Co-authored-by: Jeffrey <9938813+Raphire@users.noreply.github.com> --- Win11Debloat.ps1 | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/Win11Debloat.ps1 b/Win11Debloat.ps1 index 5688b7d..63c9a6f 100644 --- a/Win11Debloat.ps1 +++ b/Win11Debloat.ps1 @@ -243,6 +243,37 @@ else { Start-Transcript -Path $script:DefaultLogPath -Append -IncludeInvocationHeader -Force | Out-Null } +# When Group Policy overrides Run.bat's Process-scope Bypass, marked PowerShell source files +# can prompt as they are dot-sourced. Outside -WhatIf, remove Mark-of-the-Web only from marked +# .ps1, .psm1, and .psd1 files under Scripts; leave all other downloaded files untouched. +# See issue #720. +if (-not $WhatIfPreference) { + $gpoExecutionPolicySet = (Get-ExecutionPolicy -Scope MachinePolicy) -ne 'Undefined' -or + (Get-ExecutionPolicy -Scope UserPolicy) -ne 'Undefined' + + if ($gpoExecutionPolicySet) { + $markedScriptFiles = @(Get-ChildItem -LiteralPath $scriptsPath -Recurse -File | + Where-Object { $_.Extension -in '.ps1', '.psm1', '.psd1' } | + Where-Object { + Get-Item -LiteralPath $_.FullName -Stream * -ErrorAction SilentlyContinue | + Where-Object { $_.Stream -eq 'Zone.Identifier' } + }) + + if ($markedScriptFiles.Count -gt 0) { + Write-Host "Unblocking $($markedScriptFiles.Count) PowerShell file(s)..." + $unblockErrors = @() + $markedScriptFiles | Unblock-File -ErrorAction SilentlyContinue -ErrorVariable +unblockErrors + + if ($unblockErrors.Count -gt 0) { + Write-Warning "Failed to unblock $($unblockErrors.Count) PowerShell file(s)." + } + else { + Write-Host "All files were unblocked successfully." + } + } + } +} + # Check if the device is domain-joined and warn the user (Group Policy may override changes) try { $computerSystem = Get-CimInstance Win32_ComputerSystem -ErrorAction SilentlyContinue