Tabelle erstellen: Unterschied zwischen den Versionen

Aus Wiki-WebPerfect
Wechseln zu: Navigation, Suche
(Die Seite wurde neu angelegt: „== Offizielle Tabelle erstellen == <source lang="powershell"> $TableName = "SampleTable" #Create Table object $table = New-Object system.Data.DataTable “$Ta…“)
 
K
 
(2 dazwischenliegende Versionen des gleichen Benutzers werden nicht angezeigt)
Zeile 1: Zeile 1:
== Offizielle Tabelle erstellen ==
+
== Offizielle PowerShell Tabelle erstellen ==
 
<source lang="powershell">
 
<source lang="powershell">
 
$TableName = "SampleTable"
 
$TableName = "SampleTable"
Zeile 28: Zeile 28:
  
 
#NOTE: Now you can also export this table to a CSV file as shown below.
 
#NOTE: Now you can also export this table to a CSV file as shown below.
$tabCsv = $table | export-csv $getPathoutputMACAddress.csv -noType
+
$tabCsv = $table | export-csv $getPathoutput.csv -noType
 
</source>
 
</source>
  
Zeile 39: Zeile 39:
 
$ObjectTable = @($obj1,$obj2)
 
$ObjectTable = @($obj1,$obj2)
 
</source>
 
</source>
 +
 +
 +
 +
 +
 +
''Quellen: https://stackoverflow.com/questions/26479517/how-can-i-create-a-table-in-powershell-using-variables-and-data-i-input''
 +
  
  
  
 
[[Kategorie:PowerShell]]
 
[[Kategorie:PowerShell]]

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