<# Function for generating data tables. Leave the New-Table function as it is and play with the stuff below it.
AMIABTY...
All my ideas are belong to you. #>
cls
function New-Table {
param([string]$TableName, [hashtable]$Columns)
Write-Host 'Table:' $TableName
$Table = New-Object system.Data.DataTable $TableName
foreach ($Column in $Columns.GetEnumerator()) {
Write-Host "$($Column.Name): $($Column.Value)"
$NewColumn = New-Object system.Data.DataColumn $($Column.Name),($($Column.Value))
$Table.columns.add($NewColumn)
}
return, $Table
}
# Specify the Columns.
$GenerateTheseColumns = @{
'SHA1' = [string];
'DateTime' = [DateTime];
'FileName' = [string]
}
# Create the table.
$SHA1Table = New-Table -TableName 'SHA1Table' -Columns $GenerateTheseColumns
# Create rows.
$Row1 = $SHA1Table.NewRow()
$Row2 = $SHA1Table.NewRow()
# Enter data in the rows.
$Row1.SHA1 = "A"
$Row1.FileName = "1"
$Row2.SHA1 = "B"
$Row2.FileName = "2"
# Add the rows to the table.
$SHA1Table.Rows.Add($Row1)
$SHA1Table.Rows.Add($Row2)
# Display the table.
$SHA1Table # | format-table -AutoSize
# http://stackoverflow.com/questions/9015138/powershell-looping-through-a-hash-or-using-an-array
# http://stackoverflow.com/questions/11562634/powershell-returning-data-tables-without-rows-in-functions