Forum Discussion
Schulzi
Feb 25, 2021Brass Contributor
foreach loop, self creating variables
I have following (part) of my script: $form_Users = New-Object System.Windows.Forms.Form
$form_Users.Text = "Users to add"
$form_Users.Size = New-Object System.Drawing.Size (300,200)
$form_Us...
- Feb 25, 2021
You'd just need to use an array and populate that within the foreach loop:
$selected_Users = $selected_Output -split "," $AllMail = @() foreach($User in $selected_Users) { $selected_email = "$User@mail.com" $AllMail += ,$selected_email } $AllMailwhich would leave you with $AllMail as an array containing all the e-mail addresses.
If you wanted a single variable rather than an array, with a comma separated list, you'd do this at the end:
$EmailList = $AllMail -join ","
CoasterKaty
Feb 25, 2021MVP
You'd just need to use an array and populate that within the foreach loop:
$selected_Users = $selected_Output -split ","
$AllMail = @()
foreach($User in $selected_Users)
{
$selected_email = "$User@mail.com"
$AllMail += ,$selected_email
}
$AllMailwhich would leave you with $AllMail as an array containing all the e-mail addresses.
If you wanted a single variable rather than an array, with a comma separated list, you'd do this at the end:
$EmailList = $AllMail -join ","