Dec 21 2021 01:32 PM - edited Dec 22 2021 06:49 AM
Hello,
I have a small csv file that I import in Powershell into a variable. Here it is (as I can't seem to upload a file):
"RGG","BAS","IMT"
"keepass","webex","firefox"
"acrobat","ciscoany","teams"
"","keepass","Visio"
"","Acrobat","Project"
"","gekkotArt",""
After importing it I can examine $myCsvVar in many ways.
For example:
$myCsvVar= Import-Csv -Path C:\temp\csvFile.csv -Delimiter ","
$myCsvVar
$myCsvVar.RGG
$myCsvVar.RGG[1]
$myCsvVar[1]
$myCsvVar[1,2]
$myCsvVar.gettype()
$myCsvVar.RGG.gettype()
$myCsvVar[1].gettype()
$myCsvVar|get-member
However hard I try, I am not able to create such a variable from within Powershell.
Would anybody here know how to do that?
The reason is that I have to construct a variable as an object that I then can use with export-csv.
Thank you.
Dec 23 2021 01:11 AM
Dec 23 2021 07:35 AM
Jan 05 2022 02:43 PM
Hi,
One solution would be to create an array of pscustomobjects like so:
$myArr=@()
for($i=0; $i -lt 10; $i++){
$myArr = $myArr + [PSCustomObject]@{AAA = ""; BBB = ""; CCC = "" }
}
Afterwards I can set any cell of the matrix:
$myArr[2].aaa="note"
The only problem is that I have more then three keys, all through to ZZZ.
As I don't want to type them all, I wonder whether I can get this done programmatically?
I tried to build a string variable and put it within the curly brackets of the hashtable. But the compiler does not allow for that as it requires a hard coded equal sign.
Anybody have an idea?
Thank you