Last active
June 22, 2024 05:49
-
-
Save refactorsaurusrex/9aa6b72f3519dbc71f7d0497df00eeb1 to your computer and use it in GitHub Desktop.
How to call 'File.AppendAllLines' with PowerShell
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thank you so much!