Tabelle erstellen: Unterschied zwischen den Versionen

Aus Wiki-WebPerfect
Wechseln zu: Navigation, Suche
K
K
 
Zeile 44: Zeile 44:
  
  
Quellen:
+
''Quellen: https://stackoverflow.com/questions/26479517/how-can-i-create-a-table-in-powershell-using-variables-and-data-i-input''
''*https://stackoverflow.com/questions/26479517/how-can-i-create-a-table-in-powershell-using-variables-and-data-i-input''
+
  
  

Aktuelle Version vom 11. August 2017, 09:05 Uhr

Offizielle PowerShell Tabelle erstellen

$TableName = "SampleTable"
 
#Create Table object
$table = New-Object system.Data.DataTable “$TableName”
 
#Define Columns
$col1 = New-Object system.Data.DataColumn ColumnName1,([string])
$col2 = New-Object system.Data.DataColumn ColumnName2,([string])
 
#Add the Columns
$table.columns.add($col1)
$table.columns.add($col2)
 
#Create a row
$row = $table.NewRow()
 
#Enter data in the row
$row.ColumnName1 = "A" 
$row.ColumnName2 = "1" 
 
#Add the row to the table
$table.Rows.Add($row)
 
#Display the table
$table | format-table -AutoSize 
 
#NOTE: Now you can also export this table to a CSV file as shown below.
$tabCsv = $table | export-csv $getPathoutput.csv -noType


Tabelle mittels PowerShell-Objekte erstellen

$obj1 = New-Object PSObject -Property @{"Spalte 1"="Wert 1"; "Spalte 2"="Wert 1"}
$obj2 = New-Object PSObject -Property @{"Spalte 1"="Wert 2"; "Spalte 2"="Wert 2"}
$ObjectTable = @($obj1,$obj2)



Quellen: https://stackoverflow.com/questions/26479517/how-can-i-create-a-table-in-powershell-using-variables-and-data-i-input