Átomo
10Sc
Arquivos e pastas · Windows

Set-Content / Out-File

Abrir na tabela

Definição

Gravam texto em arquivo. Set-Content sobrescreve, Add-Content acrescenta, Out-File recebe de um pipe. > e >> também funcionam.

Atenção à codificação: use -Encoding utf8 para arquivos lidos por outras ferramentas.

Exemplos

1. Gravar e acrescentar
Set-Content -Path notes.txt -Value "first line"
Add-Content -Path notes.txt -Value "second line"
2. De um pipe
Get-Process | Out-File processes.txt
Get-ChildItem > listing.txt
3. Com codificação definida
"id,name" | Out-File -FilePath out.csv -Encoding utf8

No mesmo grupo