Search code examples
powershellpromptselect-string

running PowerShell cmd with pipeline in cmd prompt


I want to run the cmd select-string in cmd prompt to find some string recursive.

But it can't work while the cmd have the pipeline(|) character, and it will work by running the cmd in the powershell prompt.

enter image description here

The Chinese error info is:

'select-string' is not recognized as an internal or external command,
operable program or batch file.

Can anyone know how to fix this? Make the pipeline sense in the cmd prompt or use select-string to find string recursive.

I want to make it work in my case, thanks a lot.


Solution

  • As suggested in the comment, you need to use pipe in PowerShell, not in cmd. You can do it like this:

    powershell "Get-ChildItem | Select-String -Pattern 'something something'"
    

    Note: Of course it's just a workaround, I'd still suggest to just run PowerShell cmdlets in PowerShell, not in cmd. It can save you from the headache of troubleshooting non-working code.