Skip to content

Instantly share code, notes, and snippets.

@andineck
Created April 22, 2015 13:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andineck/2f0784726086fb352c5c to your computer and use it in GitHub Desktop.
Save andineck/2f0784726086fb352c5c to your computer and use it in GitHub Desktop.
powershell read write file
$filePath = "test.txt"
# write append to file
echo 'halloo' >> $filePath
# write empty file
echo $null > $filePath
# read file into variable
$content = "";
try {
$content = [IO.File]::ReadAllText($filePath)
} catch [System.Exception] {
Write-Host "File missing"
}
$content.Length
if ( $content.Length ) { Write-Host "not empty" }
# delete file
rm $filePath
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment