PowerShell File Creation Writing

Create and Write Files Simultaneously in PowerShell

In Bash, you can do this with the cat command and heredoc, but I want to create and write files simultaneously in PowerShell. Use <code>Set-Content</code>. There's also <code>Add-Content</code>, but that hasn't been tested. With this, a file with text is created in the current directory.

Shou Arisaka
1 min read
Nov 25, 2025

This article introduces how to create and write files simultaneously in PowerShell.

In Bash, You Can Do It with the cat Command and Heredoc

In bash,

cat << EOT > file.md
hoge
hoge
EOT

You can do it like this, but I want to do this in PowerShell.

PowerShell Heredoc

echo @"
hoge
  $fuga
piyo
"@
You can write heredocs by enclosing double quotes or single quotes with @. Newlines are required before and after the opening and closing @.
## How to Do It Use Set-Content. There's also Add-Content, but that hasn't been tested. ``` Set-Content -Path "_dev.md" -Force -Value @' hoge fuga '@ ``` With this, a file with text is created in the current directory.

Share this article

Shou Arisaka Nov 25, 2025

๐Ÿ”— Copy Links