Out-File
Send output to a file
Get-ChildItem | Out-File -FilePath .\listing.txt
- Works on
- WindowsLinuxmacOS
- PowerShell
- 5.1 and later
- Reference
- Microsoft Learn: Out-File
- PowerShell 5.1 Writes UTF-16 by default, which some programs cannot read. Add -Encoding utf8.
- PowerShell 7 Writes UTF-8 (no BOM) by default.
Redirects formatted output to a file. Good for logs and quick dumps. For structured data, use Export-Csv or ConvertTo-Json.
-Append adds instead of replacing. > is an alias for Out-File. >> appends.
Try this
Get-Date | Out-File -FilePath .\run.log -Append
Coming from another shell
| Shell | What you might type |
|---|---|
| bash / zsh | ls > listing.txt |
| cmd.exe | dir > listing.txt |
More in From bash and From cmd.