0

In my PowerShell script, I'd like to use the output of a tool like git.

For example, the command line

git status

returns

# On branch master
nothing to commit (working directory clean)

Now I tried to use this output in the following pipeline command:

git status | $_.Contains("nothing to commit")

But I get the error

Expressions are only allowed as the first element of a pipeline.

What am I doing wrong?

2 Answers 2

2
$msg = [string](git status) | where { $_.Contains("nothing to commit") }
Sign up to request clarification or add additional context in comments.

Comments

2

You can use select-string:

git status | select-string "nothing to commit"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.