How to add values to separate lines in an array?

I am trying to figure out how to create new lines where each testuser is contained on its own line element.

When I run the following code, the testusers all get bunched up together under the Value property heading.

$AdUser = @(“TestUser1”, “TestUser2”, “TestUser3”)

$Array = @{}

Foreach ($User in $ADUser)
{
$UPN = $User + “@myemail.com

$Array['EmailAddress'] += $upn

}

$Array

Can someone help me out with this, please?

Thanks a bunch, I appreciate it.

Hi.

The $Array is declared as a hashtable so you would add entries to that one,

$AdUser = @("TestUser1", "TestUser2", "TestUser3")

$Array = @{}

Foreach ($User in $ADUser) {

   $UPN = $User + "@myemail.com"
   $Array.add($user,$UPN)

}

$Array

Stein

Dave Wyatt: Edited as per OP’s request.

Stein that worked!

I also was playing around and I came up with this too that works as well:

$ADUser = @(“TestADUser1”, “TestADUser2” , “TestADUser3”)

$Array = @()
Foreach ($User in $ADUser)
{
$Email = $User + “@myemail.com

$OutputObj = New-Object -TypeName PSobject             
$OutputObj | Add-Member -MemberType NoteProperty -Name Email -Value $Email 

$Array += $OutputObj        

}

$Array

Thanks for your help