You may have had to store a line in a variable until it was complete and then write it to the file. Or you might have had to do something like this.
001
|
"$(Get-Date) - Computers accessed: $($Computers.Name -join ", ")" | Out-File $LogFile -Append
|
In PowerShell 5, a new parameter was added to Out-File, Set-Content and Add-Content, -NoNewLine.
So now, we can do something like this:
001
002 003 |
Get-Date | Out-File $LogFile -Append -NoNewline
" - Computers accessed: " | Out-File $LogFile -Append -NoNewline $Computers.Name -join ", " | Out-File $LogFile -Append |
(Yes, it's a stupid example. But you see what I'm getting at.)
And of course it works with the other ones as well.
001
002 003 |
$X | Out-File $LogFIle -NoNewline
$X | Set-Content $LogFile -NoNewLine $X | Add-Content $LogFile -NoNewLine |
No comments:
Post a Comment