Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Remove newline in write-output

Status
Not open for further replies.

HHaskel

Programmer
Jun 14, 2002
46
SE
I use this script to list all paths that are longer than 245 characters and it works as it should ecept that I get newline between length and the path.
Code:
get-childitem -r | % {if ( $_.FullName.Length -gt 245) {write-output $_.FullName.Length $_.FullName}} | tee-object -filepath c:\pathlength.txt
How can I get the length and the path on the same line?

BR
Hakan
 
The reason you're seeing this behaviour is that you're passing two values into Write-Output. If you want them on the same line you may find it most appropriate to use the two values within a single string:

Get-ChildItem -Recurse | %{
if ($_.FullName.Length -gt 245) {
write-output "$($_.FullName.Length) $($_.FullName)"
}
} | Tee-Object -filepath c:\pathlength.txt

Your formatting options aren't limited to that, so if it's not outputting as you'd like please say.

HTH

Chris
 
Works perfect.

Thank you.

Best Regards
Hakan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top