PoshCode Archive  Artifact [f86fadcce7]

Artifact f86fadcce7d5900d5d67a52baf9302278a357259a3174fd01a8a4598d206fbec:

  • File New-FullDataSet.ps1 — part of check-in [7873b821dd] at 2018-06-10 13:07:55 on branch trunk — Generates a simple dataset based on the files in the current directory. I whipped this up while answering questions about databinding because I needed to be able to create multiple DataSets/DataTables easily, without needing an actual database. (user: Joel Bennett size: 1423)

# encoding: ascii
# api: powershell
# title: New-FullDataSet
# description: Generates a simple dataset based on the files in the current directory.  I whipped this up while answering questions about databinding because I needed to be able to create multiple DataSets/DataTables easily, without needing an actual database.
# version: 0.1
# author: Joel Bennett
# license: CC0
# x-poshcode-id: 2262
# x-archived: 2010-09-26T20:50:54
#
#
## Generate two dummy datatables in a dataset for testing
$global:dt1 = New-Object system.data.datatable "Times"
$global:dt2 = New-Object system.data.datatable "Properties"
$global:ds = New-Object system.data.dataset "dataset"
$null = $ds.Tables.Add( $dt1 )
$null = $ds.Tables.Add( $dt2 )

$global:cols1 = ls|?{!$_.PsIsContainer}| gm -type Properties "Name", "CreationTime", "LastAccessTime", "LastWriteTime"
$global:cols2 = ls|?{!$_.PsIsContainer}| gm -type Properties "Name", "Length", "Extension", "Mode", "FullName"

foreach($c in $cols1){
	$null = $dt1.Columns.Add( $c.Name, $($c.Definition -split " ")[0] )
}
foreach($c in $cols2){
	$null = $dt2.Columns.Add( $c.Name, $($c.Definition -split " ")[0] )
}

foreach($f in ls|?{!$_.PsIsContainer}){ 
	$null = $dt1.LoadDataRow( @($cols1 | % { $f.$($_.Name) }), $null )
	$null = $dt2.LoadDataRow( @($cols2 | % { $f.$($_.Name) }), $null )
}

return $ds

# boots { datagrid -itemssource $dt.DefaultView }