Display variabele output

Hello,

I love to find out how to modify the output of a variabele.
In this variabele I have or 1 or more then 1 user.

For example:

$users = “Pieter”,“Ammy”, “Lopey”

write-output “The users $users are now Member of the Group” | set-clipboard


This results in:
" The users Pieter Ammy Lopey are now Member of the Group"

How can I edit this to get a line like:
The User(s) Pieter , Ammy and Lopey are now member of the Group"

thanx in advance

Hi, welcome back :wave:

What have you tried so far?

$users is an array, and you can use the -join operator to make a single string from the array elements.

$numbers = 'one','two','three'
$numbers -join '-*-'

Array elements have an index, starting at 0, and the array has a Count property which tells you how many elements are in the array. You can use the index value -1 to get the last element in the array.

$numbers = 'one','two','three'
$numbers[0,-1] -join '-*-'

Knowing all that, and with a bit of experimentation, you should be able to figure out how to get the result you’re after. Give it a go and let us know if you need further help.

When posting code in the forum, please can you use the preformatted text </> button. It really helps us with readability, and copying and pasting your code (we don’t have to faff about replacing curly quote marks to get things working).

How to format code on PowerShell.org

2 Likes