Erstellen eines Hashtable aus einer CSV Datei mit Powershell
In diesem Beitrag zeige ich, mit einem PS-Skript, wie aus einer CSV Datei mit Powershell ein Hashtable erzeugt werden kann. Es gibt sicher viele andere Alternativen, wie aus einer CSV Dateie ein Hashtable erzeugt werden kann, falls ihr noch andere Skripte habt dann immer her damit.
#Create Hashtable $varHashTable = @{}; $varCSV = Get-Content Test.csv; #Split Variable $varSplitCSV = $varCSV.Split(";"); #Read the first ROW in the CSV $col1End = 0; $countCol= 0; foreach($row in $varSplitCSV){ if($row -eq "Test2"){ $countCol++ break; } else { $countCol++ } } ; #Write the Hashtable for($Col=0;$Col -lt $countCol;$Col++){ $varHashTable[$varSplitCSV[$Col]]= $varSplitCSV[($countCol+$Col)]; }; $varHashTable
Falls es noch bessere Powershell Skripte oder Anregung/Verbesserungen zu diesem Powershell Skript gibt, schreibt mir einfach.
Download der CSV Datei
Download “Test.csv” Test.csv – Downloaded 323 times – 39 B
Download “Test.csv” Test.csv – Downloaded 323 times – 39 B
Dieser Artikel wurde (895) mal gelesen
Sharing is Caring