, , , , , /.
, :
:
Ad-hoc change. -Encoding Out-File Set-Content, .
, >/>> ad-hoc, .
[PSv3 +] ( ): $PSDefaultParameterValues (. Get-Help about_Parameters_DefaultValues), :
Out-File >/>> PSv5.1 [2]. < > UTF-8, , :
$PSDefaultParameterValues['Out-File:Encoding']='UTF8'
Set-Content, Add-Content:
$PSDefaultParameterValues['Set-Content:Encoding'] = $PSDefaultParameterValues['Add-Content:Encoding'] ='UTF8'
/ ; , $PSDefaultParameterValues['*:Encoding']='UTF8', cmdlets, -Encoding, , , -Encoding .
, , cmdlets, :
$enc = 'UTF8; $PSDefaultParameterValues += @{ 'Out-*:Encoding'=$enc; 'Set-*:Encoding'=$enc; 'Add-*:Encoding'=$enc; 'Export-*:Encoding'=$enc }
Caveat: $PSDefaultParameterValues , .
script/function , $PSDefaultParameterValues, -, ($PSDefaultParameterValues = @{}), ($PSDefaultParameterValues = $PSDefaultParameterValues.Clone())
[Microsoft.PowerShell.Commands.MatchInfo] Select-String:
, Out-File, ( , ).
.psobject.ToString() , Set-File, ( , , , -Path/-LiteralPath), .
, | Select-Object -ExpandProperty Line | ForEach-Object Line, , Out-File Set-Content ( ).
PS: LotPing : , , foreach ForEach-Object (, , foreach, ).
ForEach-Object cmdlet $_: ( -Process) script , $_ .
($_) foreach (ForEach-Object) : $null: $_, , , script - $null, (...) , $null, .
[1] , ASCII : '0x{0:x}' -f $('ä' | Set-Content t.txt; $b=[System.IO.File]::ReadAllBytes("$PWD\t.txt")[0]; ri t.txt; $b) 0xe4 en-US, Windows-1252 ä ( Unicode, ).
-Encoding ASCII, 0x3f, ?, , ASCII, , ASCII. .
[2] PetSerAl , , > >> Out-File [-Append], , Out-File >/>>; , $PSDefaultParameterValues Out-File >/>>.
Windows PowerShell v5.1 - , .
PetSerAl .