0

我正在尝试读取 csv 文件并存储在 hasmap 中。下面是我正在使用的代码。

$data | ForEach-Object {
  $ht = @{}
  $_.psobject.Properties |
    #Get only the grouped properties (that have a number at the end)
    Where-Object { $_.Name -match '\d+$' } |
    #Group properties by param/group number
    Group-Object {$_.Name -replace '\w+(\d+)$', '$1' } | ForEach-Object {
      $param = $_.Group | Where-Object { $_.Name -match 'param' }
      $value = $_.Group | Where-Object { $_.Name -match 'value' }

      #If property has value
      if($value.value -ne ""){
        #Add to hashtable
        $ht.add($param.Value,$value.Value)
      }
    }

  $ht
}

下面是 的输出$ht。我$null为其中一个字段获得 1 个值OrgId

名称 值
---- -----
{orgId, } {1000002, $null}
输入 CSV 文件
代码页 MS1252
代理ID 00000208000000000002
名称 infa_param_file_Pravakar
日期格式 MM/dd/yyyy HH:mm:ss
数据库 C:\\Program Files\\Informatica Cloud Secure A

CSV 样本:

"param1","value1","param2","value2","param3","value3","param4","value4","param5","value5","param6","value6","param7 ","value7","param8","value8","param9","value9","param10","value10","param11","value11"
"orgId","000002","name","infa_param_file_Pravakar","agentId","00000208000000000002","dateFormat","MM/dd/yyyy HH:mm:ss","database","C:\\程序文件\\Informatica Cloud Secure Agent\\main\\rdtmDir\\userparameters","codepage","MS1252","type","CSVFile","","","","","", "","",""
4

0 回答 0