Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Tuesday, February 14, 2017 7:16 AM
Hello
I am generating log with csv extension. I am adding content as
ac $userLog $userLogBuffer -Encoding UTF8 -Force
I am passing location in $userLogBuffer. If I passed location as c:\logs, it works fine.
But when I give another location "c:\test logs" or c:\test logs, it throws error as
A parameter cannot be found that matches parameter name 'Encoding'.
Please let me know how to handle this situation.
Regards
Avian****
All replies (4)
Tuesday, February 14, 2017 7:44 AM
help export-Csv -full
Add-Content cannot create a CSV file.
\(ツ)_/
Tuesday, February 14, 2017 7:51 AM
Hi
You probably need to create the file with Set-Content -Path $userLogBuffer -Value $userLog -Encoding UTF8. Add-Content will append data to an existing file and will respect the encoding of the file. Another option would be to use Out-File -Filepath $UserLogBuffer -InputObject $UserLog -Encoding UTF8.
On a side not, please use full cmdlet names and parameter name/value and avoid aliases.
Cheers
Tore
Tuesday, February 14, 2017 7:54 AM
Add-Content will create the file if one does not exist.
The issue is likely due to using nulls using positional parameters.
\(ツ)_/
Tuesday, February 14, 2017 8:38 AM
Hi,
I think you are missing a filename in the $userlog variable unless you are trying to write to all files in the directory?
This works:
$userlog = Join-Path -Path "c:" -ChildPath "test logs" | Join-Path -ChildPath "file.txt"
$userlogbuffer = "write this to the file"
Add-Content -Path $userlog -Value $userlogbuffer -Encoding UTF8
Cheers
Tore