If I got you right you can use the ternary operator.
That’s a tricky question. But if Bing, Google or ChatGPT fail you can still ask humans … us … here … or StackOverflow or Reddit or …
BTW: When you post code, sample data, console output or error messages please format it as code using the preformatted text button ( </> ). Simply place your cursor on an empty line, click the button and paste your code.
Oh well, before asking my question I spent half an hour trying this, and then I realised that perhaps this was not a PowerShell syntax.
PowerShell underlines the question mark in red, and tells me that it is an unexpected token.
I presume that this is a question of version of PowerShell ?
I was using Windows PowerShell, 5.1.22621.2428.
Well, before posting, I took the time to read a notice that explained I had to type two ticks before and two ticks after a short text, or three ticks alone on a line before, and the same after, when it is a code of several lines.
I just corrected my question to use the button.
It seems it requires some habit to see the difference.
Pardon me to insist, I used the Stylus extension to change the background of the code.
I see the same background for the text I formatted with the button, and for the one I framed with ticks (either one or two before and after).
It means that in the source of the page it is framed by < code> tags.
Oooops, sorry, I forgot to mention that. Yes, it is a feature we don’t have in Windows PowerShell (version 5.1). If you need it you have to use PowerShell core
(version 7.x.x).
If you want to post a small piece of code inside plain text you quote it with a single backtick on each side. If you want to post a code block you place 3 consecutive backticks on an emptly line before and after the code block. Or you simply use the button of the post editor (</>). If you’ve selected a whole line of text/code it will create a code block. And if you just selected some characters on a line of text it will make the code inline.
Oh, the function did not receive its string arguments, did I commit a mistake?
And if I try to declare [bool] as the type of the first parameter, I have syntax errors.
If I put “yes” or “no” in the code of the function without taking care of the arguments then I have the results, but it was not the aim.
Well, it seems the message was received the first time.