Quantcast
Channel: /r/powershell – How to Code .NET
Viewing all articles
Browse latest Browse all 8793

Question: Dealing with control characters in strings

$
0
0

Hi everyone,

Today I’m dealing with some auto-remediation tasks. Specifically, I’m working with sfc to identify and resolve any integrity violations. Ideally, I’d like to have my script check the output of sfc /verifyonly and make decisions from there.

Unfortunately, sfc does two things that make parsing output more difficult than it needs to be. It:

  • Adds a null character after every character
  • Uses backspace characters to overwrite previous output

This isn’t an issue in the shell itself, but I’m forced to pump my eventual output to a text file by our RMM tool. This means that the nice

Beginning system scan. This will take some time. Beginning verification phase of system scan. Verification 100% complete. Windows Resource Protection did not find any integrity violations. 

becomes a hot mess. Feel free to try it on your own, I don’t want to clutter this post.

I already know how to deal with null characters (some of our vendors’ executables do the same thing) with:

$output = $output -replace "", "" 

but the backspace characters persist. My plan is to dump everything in the line prior to the last backspace character, but in general, what does everyone do to handle these special characters in their output?

submitted by /u/emceetate
[link] [comments]

The post Question: Dealing with control characters in strings appeared first on How to Code .NET.


Viewing all articles
Browse latest Browse all 8793

Trending Articles