SHARE
    TWEET
    J2897

    Generate Data Tables

    May 6th, 2016
    536
    0
    Never
    Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
    1. <# Function for generating data tables. Leave the New-Table function as it is and play with the stuff below it.
    2. AMIABTY...
    3. All my ideas are belong to you. #>
    4. cls
    5. function New-Table {
    6. param([string]$TableName, [hashtable]$Columns)
    7. Write-Host 'Table:' $TableName
    8. $Table = New-Object system.Data.DataTable $TableName
    9. foreach ($Column in $Columns.GetEnumerator()) {
    10. Write-Host "$($Column.Name): $($Column.Value)"
    11. $NewColumn = New-Object system.Data.DataColumn $($Column.Name),($($Column.Value))
    12. $Table.columns.add($NewColumn)
    13. }
    14. return, $Table
    15. }
    16. # Specify the Columns.
    17. $GenerateTheseColumns = @{
    18. 'SHA1' = [string];
    19. 'DateTime' = [DateTime];
    20. 'FileName' = [string]
    21. }
    22. # Create the table.
    23. $SHA1Table = New-Table -TableName 'SHA1Table' -Columns $GenerateTheseColumns
    24. # Create rows.
    25. $Row1 = $SHA1Table.NewRow()
    26. $Row2 = $SHA1Table.NewRow()
    27. # Enter data in the rows.
    28. $Row1.SHA1 = "A"
    29. $Row1.FileName = "1"
    30. $Row2.SHA1 = "B"
    31. $Row2.FileName = "2"
    32. # Add the rows to the table.
    33. $SHA1Table.Rows.Add($Row1)
    34. $SHA1Table.Rows.Add($Row2)
    35. # Display the table.
    36. $SHA1Table # | format-table -AutoSize
    37. # http://stackoverflow.com/questions/9015138/powershell-looping-through-a-hash-or-using-an-array
    38. # http://stackoverflow.com/questions/11562634/powershell-returning-data-tables-without-rows-in-functions
    Advertisement
    Add Comment
    Please, Sign In to add comment
    Public Pastes
    We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
    Not a member of Pastebin yet?
    Sign Up, it unlocks many cool features!

    AltStyle によって変換されたページ (->オリジナル) /