syntax question when importing data from CSV file
hello all,
i'm wondering when need use double quotes when referencing column in csv file. example, following code pulls data csv file has 1 column called "samaccountname":
import-csv c:\results.csv | foreach-object { $name1 = ($_.samaccountname) $name2 = ($_."samaccountname") $name1 $name2 } both $name1 , $name2 work fine. know is, when reference csv column double quotes in code? when csv column name not correspond ad attribute, i.e. if above column name called "samaccountname users"?
hi,
you need quote property name when property has space in it. take input:
attributeone,attribute two
a1 data one,a2 data one
a1 data two,a2 data two
save input.csv , run this:
import-csv .\input.csv | foreach { $name1 = $_.attributeone $name2 = $_.'attribute two' $name1 $name2 } edit: aside, use single quotes in situation. use double quotes in powershell when explicitly want variable expand, otherwise ever use single quotes. took getting used to, i'm glad forced myself relearn.
don't retire technet! - (don't give yet - 12,830+ strong , growing)
Windows Server > Windows PowerShell
Comments
Post a Comment