1

I'm try to replace the good old systeminfo and findstr with Get-ComputerInfo and Select-String

systeminfo | findstr Boot

Get-ComputerInfo | Select-String boot

but please have a look at the attachment

image attachment

  • there is no logic here!

I'm not talking about the fact that findstr no longer needs to distinguish between uppercase and lowercase in Get-ComputerInfo. and I need it with systeminfo

why Select-String works with systeminfo but not with Get-ComputerInfo?

how to combine these two commandos? or maybe you just can't? maybe there is no logic here?

scribe
  • 21
  • 4
  • 2
    `Get-ComputerInfo` doesn't output raw text, so `Select-String` is probable not the right tool for dissecting the output. Give `Get-ComputerInfo |Select-Object *boot*` a go instead :) – Mathias R. Jessen Nov 16 '22 at 13:18
  • ok but im also try with string parameter [string]$info = Get-ComputerInfo $info | select-string with an even weirder result - error! – scribe Nov 16 '22 at 13:20
  • Why? What is it that you're trying to do that you can somehow only use `Select-String` for? – Mathias R. Jessen Nov 16 '22 at 13:22
  • In short: Unfortunately, [`Select-String`](https://docs.microsoft.com/powershell/module/microsoft.powershell.utility/select-string) uses simple `.ToString()` stringification on its input objects rather than using the rich for-display representation produced by PowerShell's output-formatting system that you see when printing to the console. The workaround is to pipe to `oss` (a wrapper for `Out-String -Stream`) first; see the linked duplicate for details. (Generally, it is more robust to select / query specific properties via `Select-Object` / `Where-Object` instead.) – mklement0 Nov 16 '22 at 13:24
  • and if Get-Computernfo is not a string why does it work with findstr ? – scribe Nov 16 '22 at 13:25
  • In other words: To search `Get-ComputerInfo`'s output by its rich, for-display _string representation_ (as you would see in the console) with `Select-String`, use `Get-ComputerInfo | oss | Select-String boot`. The reason it works with `findstr` is that when piping to _external programs_ PowerShell _always_ sends the rich output formatting, because it has to send (meaningful) _text_ rather than objects. – mklement0 Nov 16 '22 at 13:30
  • I agree that `oss` shouldn't be necessary, and that `Select-String` should _by default_ use the richly formatted string representation rather than the `.ToString()` result for non-string input objects, as suggested in [GitHub issue #10726](https://github.com/PowerShell/PowerShell/issues/10726). – mklement0 Nov 16 '22 at 13:33
  • Glad to help, @scribe. I've just updated the linked answer to structure it better, and it now also explains why piping to _external programs_ such as `findstr.exe` doesn't surface the problem. – mklement0 Nov 16 '22 at 14:08

0 Answers0