Skip to content

Instantly share code, notes, and snippets.

@refactorsaurusrex
Last active August 1, 2023 12:53
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save refactorsaurusrex/9aa6b72f3519dbc71f7d0497df00eeb1 to your computer and use it in GitHub Desktop.
Save refactorsaurusrex/9aa6b72f3519dbc71f7d0497df00eeb1 to your computer and use it in GitHub Desktop.
How to call 'File.AppendAllLines' with PowerShell
$path = 'C:\text.txt'
$output = 'This is an output string'
# This works...
[System.IO.File]::WriteAllLines($path, $output)
# But this doesn't. WTF!
[System.IO.File]::AppendAllLines($path, $output)
# Result: 'Cannot find an overload for "AppendAllLines" and the argument count: "2".'
# However, if you cast the string to an array, the correct overload can be found:
[System.IO.File]::AppendAllLines([string]$path, [string[]]$output)
# Hooray!
@hoshang82
Copy link

thank you so much!

@cmaster11
Copy link

Oh thanks, this helped! :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment