Pipeline Variable Access Property by Variable

I tried for hours to get this to work :slight_smile: any help would be greatly appreciated as it would massively speed up merge operations.

Why is $.$something or $.$($something) a no go??

[pre]$fieldsIneed = import-csv ‘C:\Users\NickCrooks\OneDrive - ABC_CO\XYZ_CO-Data_Editing\SQL\HTABC.rpt’ #Select * from Table 1;
$xyzvend = import-csv ‘someotherfile.rpt’ #select * from table2;
#$fieldsIneed | GM -MemberType NoteProperty | Select Name, Definition | Out-GridView

$fieldsIneed | %{
$p = $_ #this property being evaluated at the moment
if($p -inotin $($xyzvend | GM -MemberType NoteProperty)){$xyzvend | Add-Member -MemberType NoteProperty -Name $p.name -Value ‘’ -force}

#$xyzvend | GM -MemberType NoteProperty | ?{$.name -like “EFT*”} #confirm success
$propsIcareabout = $xyzvend | GM -MemberType NoteProperty | ?{$
.name -like “EFT*”} | select name #easy in this case
#$propsIcareabout += ‘some other manual props if needed’

#region improve data gathering

#region merge properties

$propsIcareabout | %{
$p = $_.name
Write-verbose “Clear the Hash” -Verbose
$hash = @{} #setup merger object, you need matching keys and you can make those keys if needed

Write-Host “$($p)” -ForegroundColor Yellow
#region Object 1
#Go to object 1, git yo stuff and git out
$fieldsIneed | ?{$.vendorid -ne ‘’ -and $.vendorid -ne $null -and $(if($.ADRSCODE.gettype() -like “string”) {$.ADRSCODE.trim()}) -eq ‘PRIMARY’} | %{ #assume data cleaning is always needed

$vid = $_.vendorid.trim() #ideally no trimming or formatting needed

#Write-verbose “Found $($p) and $($vid)” -Verbose
if( -not $hash.ContainsKey($vid)){$hash.Add($vid, $_.$p)}

#Note improvement - if the entire property to be merged is null then skip next iteration
#end object 1 data gathering loop
#endregion object 1

#region object 2
write-warning “Begin Second Object - Data Write”
$xyzvend | ?{$.vendorid -ne ‘’ -and $.vendorid -ne $null} | %{
$vid = $.vendorid.trim()
write-verbose “$($vid)” -verbose
$test = '$
& $test.tostring()
[string]$omfg = $p
[string]$killmenow = $p.tostring()
#$xyzvend.$p = $crmhash[$($vid)]

write-host “$($p)” -ForegroundColor Green
#endregion object 2

Due to the time crunch here’s what I did (repeating for each field I needed)


if($hash -ne $null) {$hash = @{}}
$fieldsIneed | ?{$.vendorid -ne ‘’ -and $.vendorid -ne $null -and $(if($.ADRSCODE.gettype() -like “string”) {$.ADRSCODE.trim()}) -eq ‘PRIMARY’} | %{
$p = $.vendorid
if( -not $hash.ContainsKey($p)){$hash.Add($p, $

#add in Remaining Hours values
$xyzvend | %{
if($.vendorid -ne $null){
.“UseMasterID” = $hash[$($_.vendorid)]
#end not null

It’s simply because the dot notation is expecting a string after the dot, not a variable. You can do what you want by simply providing a string that contains a variable to resolve.


$services = Get-Service

$p = "Name"

$services | ForEach-Object {