Let us assume that the guests are Mr Jain, Mr Jacobs, Ms Sanders, Mr Shah and Mr Hugo.
- Open a new file in Visual Studio Code and, in the script pane, type the following.
$GuestsRaw = Read-Host "Enter the guest names, separated by commas" $Guests = $GuestsRaw -split ",$([regex]'[s]*')" $Guests | ForEach-Object { Write-Output "Welcome, $PSItem!" }
- Run the script, and at the prompt, type in the names of the guests:
PS> Mr Jain, Mr Jacobs, Ms Sanders, Mr Shah, Mr Hugo