As for this...
"Testing $User.OldEmailAddress
...to make it work, do it this way...
$UserInput = Import-Csv 'D:\temp\myemaildata.csv' -Delimiter ','
ForEach($User in $UserInput)
{$User.OldEmailAddress}
<#
# Results
[email protected]
#>
ForEach($User in $UserInput)
{$User.NewEmailAddress}
<#
# Results
[email protected]
#>
ForEach($User in $UserInput)
{"$User.OldEmailAddress"}
<#
# Results
@{[email protected]; [email protected]}.OldEmailAddress
#>
ForEach($User in $UserInput){"$($User.OldEmailAddress)"}
<#
# Results
[email protected]
#>
ForEach($User in $UserInput){"$($User.NewEmailAddress)"}
<#
# Results
[email protected]
#>
... no Write-Host needed since output to the screen is the PowerShell default unless you tell it otherwise. ;-}
Yet, why use that extra loop at all, for example:
Import-Csv 'D:\temp\myemaildata.csv' -Delimiter ','
<#
# Results
OldEmailAddress NewEmailAddress
--------------- ---------------
[email protected] [email protected]
#>
Import-Csv 'D:\temp\myemaildata.csv' -Delimiter ',' |
ForEach{$PSItem}
OldEmailAddress NewEmailAddress
--------------- ---------------
[email protected] [email protected]
Import-Csv 'D:\temp\myemaildata.csv' -Delimiter ',' |
ForEach{$PSItem.OldEmailAddress}
<#
# Results
[email protected]
#>
Import-Csv 'D:\temp\myemaildata.csv' -Delimiter ',' |
ForEach{$PSItem.NewEmailAddress}
<#
# Results
[email protected]
#>
$Thing.Property] in double quotes, the part before the dot is expanded. the dot and the property name are NOT expanded. this is covered rather often since it is such an easy error to make. [grin]