Hello
I keep running into this confusion - when to use foreach cmdlet in a command line and when not to? (Please note I am not talking about foreach loop construct).
For example I have seen the following 2 do not work in the same way:
import-csv input.csv | foreach {$UserPrincipalName = $_.UserPrincipalName;
Get-ADUser -filter {userprincipalname -eq $userprincipalname} -properties * | foreach { set-aduser $_ -UserPrincipalName "$($_.samaccountname)@test.local"}
}
and
import-csv input.csv | foreach {$UserPrincipalName = $_.UserPrincipalName;
Get-ADUser -filter {userprincipalname -eq $userprincipalname} -properties * | set-aduser $_ -UserPrincipalName "$($_.samaccountname)@test.local"
}
The first one above does what I want but not the second one.
Is there any logic to this?