0

I cannot get this command to output to text file. I am trying to use the out-file command.

#Trim up the URL
$data = get-content C:\Dell\Temp\urlhausCopyDL.txt
$data | ForEach-Object {
    $items = $_.split(":")
    write-host  (-join('http:',$items[1])) | Out-File "C:\Dell\Temp\Formulated.txt" -Append
}

It creates the file but it is blank.

It splits the URL and removes whatever is after the second : as we don't need it.

It outputs to Console great, but I just cant get it to write to a file!! :(

A snippet of urlhauscopyDL is here for you:
http://115.55.196.162:57955/bin.sh
http://182.240.54.209:60488/bin.sh
http://176.231.66.63:49310/.i

Thankyou For your help team :)

Santiago Squarzon
  • 41,465
  • 5
  • 14
  • 37
barge77
  • 1
  • 1
  • 3
    Well `Write-Host` writes to the console so you don't need it there. It's only meant for that. Just remove `Write-Host` and it will be fine, also `| Out-File..` can go after closing the loop instead of inside – Santiago Squarzon Dec 07 '22 at 00:54
  • 1
    YES! This worked perfectly - Thankyou!! #Trim up the URL $data = get-content C:\Dell\Temp\urlhausCopyDL.txt $data | ForEach-Object { $items = $_.split(":") (-join('http:',$items[1])) } | Out-File "C:\Dell\Temp\ParsedA.txt" -Append – barge77 Dec 07 '22 at 02:25
  • @barge77, unless you need to append to the content of a preexisting file, don't use `-Append`. The two linked duplicates address address the two problematic aspects of your approach, respectively. – mklement0 Dec 07 '22 at 03:06

0 Answers0