Hello,
I want to convert a string with spaces to use as a property name. See example below.
$filePath = ‘C:\Scripts\Data.csv’
Within the Data.csv file, there is a column header with name ‘Text with space’ and the value under this header is a value called True:
Header: Text with space
The line below the header line has a value of True. I convert this header (Text with space) to a property name and the line below it (True) to the value of the property by using the ConvertTo-Csv cmdlet like below.
$data1 = Get-Content $filePath | ConvertFrom-Csv -Delimiter ‘,’
Now, I have a PSObject array ($data2) with a property name called ‘Name’ and its property value also called ‘Text with space’, and I want to check against the elements of $data1 to see if the value of of ‘Text with space’ contains the value called ‘True’.
foreach ($a in $data2) {
foreach ($b in $data1) {
if ($b.{$a.Name} -eq 'True') {
Code to do something here..
}
}
}
$a.Name in the above loop is a string. How can I convert this string to become a property name?
Thanks.