Forum Discussion
dolphin168
May 02, 2024Copper Contributor
Import file as an array
Hi, I have the following in a script that is working fine using the following: $string = @ ("xxx", "yyy", "zzz") After I changed to the following that get from a file, it does not work: $st...
- May 02, 2024A .csv file should have headers, import-csv expects that to be there. It can be only one header... I added a Header called header on the first line...
C:\Users\HarmVeenstra> $string = @ ("xxx", "yyy", "zzz")
C:\Users\HarmVeenstra> $string.GetType()
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True True Object[] System.Array
C:\Users\HarmVeenstra> $string
xxx
yyy
zzz
C:\Users\HarmVeenstra> $string = @()
C:\Users\HarmVeenstra> $string.GetType()
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True True Object[] System.Array
C:\Users\HarmVeenstra> $string += import-csv C:\temp\file.csv
C:\Users\HarmVeenstra> $string.GetType()
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True True Object[] System.Array
C:\Users\HarmVeenstra> $string
Header
------
value1
value2
value3
But... What is the problem exactly? What are you expecting?
May 02, 2024
A .csv file should have headers, import-csv expects that to be there. It can be only one header... I added a Header called header on the first line...
C:\Users\HarmVeenstra> $string = @ ("xxx", "yyy", "zzz")
C:\Users\HarmVeenstra> $string.GetType()
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True True Object[] System.Array
C:\Users\HarmVeenstra> $string
xxx
yyy
zzz
C:\Users\HarmVeenstra> $string = @()
C:\Users\HarmVeenstra> $string.GetType()
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True True Object[] System.Array
C:\Users\HarmVeenstra> $string += import-csv C:\temp\file.csv
C:\Users\HarmVeenstra> $string.GetType()
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True True Object[] System.Array
C:\Users\HarmVeenstra> $string
Header
------
value1
value2
value3
But... What is the problem exactly? What are you expecting?
C:\Users\HarmVeenstra> $string = @ ("xxx", "yyy", "zzz")
C:\Users\HarmVeenstra> $string.GetType()
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True True Object[] System.Array
C:\Users\HarmVeenstra> $string
xxx
yyy
zzz
C:\Users\HarmVeenstra> $string = @()
C:\Users\HarmVeenstra> $string.GetType()
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True True Object[] System.Array
C:\Users\HarmVeenstra> $string += import-csv C:\temp\file.csv
C:\Users\HarmVeenstra> $string.GetType()
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True True Object[] System.Array
C:\Users\HarmVeenstra> $string
Header
------
value1
value2
value3
But... What is the problem exactly? What are you expecting?
dolphin168
May 07, 2024Copper Contributor