Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/pwsh-install.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,18 @@ function Update-PowerShellProfile([string]$Path, [bool] $Install, [bool] $UseBom
$Path = $profile.ResolvedTarget
}

# A signed PowerShell profile cannot be modified without invalidating its
# Authenticode signature, which breaks profile loading under signed
# execution policies (AllSigned/etc.). Detect such profiles and skip them
# instead of silently breaking them. See microsoft/coreutils#161.
if (Test-Path -LiteralPath $Path) {
$signature = Get-AuthenticodeSignature -LiteralPath $Path -ErrorAction Ignore
if ($null -ne $signature -and $signature.Status -ne 'NotSigned') {
Write-Warning "Skipping signed PowerShell profile '$Path': modifying it would break its Authenticode signature. coreutils commands will not be available in this profile."
return
}
}

# Get-Content uses .NET's StreamReader, so it auto-detects UTF-8/UTF-16 with BOM.
$text = Get-Content -LiteralPath $Path -Raw -ErrorAction Ignore
if (!$text) {
Expand Down