Created
June 14, 2019 02:53
-
-
Save imfioki/4cf9819b9803d0051b22fc67acf62975 to your computer and use it in GitHub Desktop.
Reporting in Powershell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Here's a brisk tutorial on a basic method of reporting within Powershell. | |
# Yes, I know custom objects exist. :) | |
# Define the name for our table | |
$tableName = "<table_name>" | |
# Create the table object | |
$table = New-Object System.Data.DataTable "$tableName" | |
# Define columns for the table | |
$col1 = New-Object System.Data.DataColumn Column1,([string]) | |
$col2 = New-Object System.Data.DataColumn Column2,([string]) | |
$col3 = New-Object System.Data.DataColumn Column3,([string]) | |
# Add the columns to the data table object | |
$table.Columns.Add($col1) | |
$table.Columns.Add($col2) | |
$table.Columns.Add($col3) | |
# Create a row to add to the table | |
$row = $table.NewRow() | |
# Add properties to the row object | |
$row.Column1 = "Value1" | |
$row.Column2 = "Value2" | |
$row.Column3 = "Value3" | |
# Add row to the table object | |
$table.Rows.Add($row) | |
# Export to CSV file for portability | |
$table | Export-Csv C:\Export.csv | |
# Export to JSON for portability | |
$table | ConvertTo-Json | Out-File C:\Export.json |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment