Skip to content

Instantly share code, notes, and snippets.

@refactorsaurusrex
Last active June 22, 2024 05:49
Show Gist options
  • Select an option

  • Save refactorsaurusrex/9aa6b72f3519dbc71f7d0497df00eeb1 to your computer and use it in GitHub Desktop.

Select an option

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 your parameters are strongly typed, the method will resolve correctly:
[System.IO.File]::AppendAllLines([string]$path, [string[]]$output)
@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