开发者

Read var directly from csv

Is it possible to read a variable directly by loading a csv?

My csv looks like this:

Var,Path

$SrcHost,\\computer

Is there a possibility to import-csv and put the path into 开发者_Python百科the var?


import-csv test3.csv | foreach-object {
iex "$($_.var) = ""$($_.path)"""
}


You can also use new-variable (nv):

import-csv csvfile.csv | % { nv -name ($_.var) -value ($_.path) }

However to make this work you have to:

  • remove the $ from the source csv
  • or, trim $ as described by the comments below
  • or, select your variable as ${$srchost}


How bout this:

Get-Content -Path test.csv | Select-Object -Skip 1 | ForEach-Object { $_.Replace(",", "=`"") +
 "`"" } | Invoke-Expression
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜