Powershell magnling ascii text -
i'm getting characters , lines when trying modify hosts files. example, select string not take out, 2 files different:
get-content -encoding ascii c:\windows\system32\drivers\etc\hosts | select-string -encoding ascii -notmatch "thereisnolinelikethis" | out-file -encoding ascii c:\temp\testfile ps c:\temp> (get-filehash c:\windows\system32\drivers\etc\hosts).hash c54c246d2941f02083b85ce2774d271bd574f905babe030cc1bb41a479a9420e ps c:\temp> (get-filehash c:\temp\testfile).hash ac6a1134c0892ad3c5530e58759a09c73d8e0e818ec867c9203b9b54e4b83566
i can confirm commands inexplicably result in line breaks in output file, in start , in end. powershell converts tabs in original file 4 spaces instead.
while cannot explain why, these commands same thing without these issues:
try code instead:
get-content -path c:\windows\system32\drivers\etc\hosts -encoding ascii | where-object { -not $_.contains("thereisnolinelikethis") } | out-file -filepath "c:\temp\testfile" -encoding ascii
Comments
Post a Comment