Now let's look at operators that were introduced in PowerShell 7.
First up is the chain operator.
The chain operator is the two ampersands together.
The way this works is if the left side expression is successful,
such as get‑process ‑id $pid,
then execute whatever is on the right side of the chain operator.
So get‑process will run, I've got the process ID,
and then I'm also going to display the number 100.
Again, this is somewhat artificial,
but I want you to be able to see what the operator is doing.
And there is the result that you might expect to see in a PowerShell 7 session.
There was the process, the process completed without error,
and so the right side of the chain operator worked,
and I get the value of 100.
If the first command fails,
then the second expression on the right side of the chain operator never runs.
So I try to run get‑process for a nonexistent ID.
I get an error.
That command does not complete successfully,
and so the second part of that chain does not run,
and I never exceed the value of 100.
The other chain operator is the two vertical bars put together.
In this case,
if the left side expression fails then run the right side expression.
So if I do get‑process for some nonexistent process,
because that fails then I get, in this case,
the number 100.
Here's an example of how you might use this in PowerShell.
If the first test succeeds, then I want to do something.
So, if I can do a test‑wsman on a computer,
in this case my local computer name, then,
that's the ampersand ampersand,
then I'm going to run Get‑CimInstance and get the
win32_bios class on that computer.
So it's a nice example of using the chain operator.
If the left side of the expression works,
or runs without error I should say,
then run whatever is on the right side of the chain operator.
Now if you wanted, for example though, to get rid of say,
I don't want to see that first command, you can pipe,
this is going to pipe the test‑wsman to Out‑Null to suppress that test result.
So all I get then is the result of the Get‑CimInstance command
on the right side of the chain operator,
the double ampersand.
So here's an example where this is not going to work.
So I'm going to try to test the $computer = "foo".
That obviously doesn't exist.
So if that works, then run Get‑CimInstance.
And then if that doesn't work, then write a warning.
So, I'm kind of combining both chain operators here.
And so I get my failure, so I never run Get‑CimInstance,
but because that first expression failed,
then I get the warning.
You'll, again, want to try these things all out for yourself.
You could also do a lot of the same things in PowerShell
scripting with an if/else statement. There is a help topic that you should take a look at.