Jason wrote:
> ok so I ended up with this:
>
> $database.Tables |% { $_.Columns | select @{Name="Schema";
> Expression={$_.Parent.Schema}}, @{Name="Table"; Expression={$_.Parent.Name}},
> Name, DataType, @{Name="MaxLength"; Expression={$_.DataType.MaximumLength}},
> @{Name="Nullable"; Expression={if($_.Nullable -eq $True){"YES"}Else{"NO"}}},
> @{Name="Precision";
> Expression={$_.DataType.NumericPrecision}},@{Name="Scale";
> Expression={$_.DataType.NumericScale}} } | Export-Csv -noTypeInformation
> $exportFileName ....which all will agree is a mess.
I find that calc'd properties inevitably grow during creation so I've taken to
separating out the scriptblock (or the whole hashtable) out to a separate
command. Here's how:
$NullableSb = {if($_.Nullable -eq $True){"YES"}Else{"NO"}}}
then you'd have something like this:
$database.tables | % { $_.columns | select @{Name=Nullable; Expr=$NullableSb} }
Or you can back out one step further:
$SchemaCol = @{
Name="Schema"
Expression={$_.Parent.Schema}
}
$TableCol = @{Name="Table"; Expression={$_.Parent.Name}}
$NullableCol = @{
Name = "Nullable"
Expr = {if($_.Nullable -eq $True){"YES"}Else{"NO"}}}
}
Then you execute it like so:
$database.tables | % { $_.columns | select $SchemaCol,$TableCol,$NullableCol }
--
Hal Rottenberg
Blog:
http://halr9000.com
Webmaster, Psi (
http://psi-im.org)
Co-host, PowerScripting Podcast (
http://powerscripting.net)