Below is the PowerShell function I created to return a table.
function GetJOINConstraints
{
[CmdletBinding()]
param(
[Parameter( Mandatory=$true)] $ConnectionString,
[Parameter( Mandatory=$true)] $tableName
)
$Conn = new-object System.Data.SqlClient.SQLConnection
$Conn.connectionString=$ConnectionString
$Conn.Open()
$Cmd = New-Object System.Data.SqlClient.SqlCommand
$Cmd.Connection = $Conn
$cmd.CommandText = "Exec TemplateTransport.usp_Get_JOINConstraints 'Action'"
#$Cmd.CommandType = [System.Data.CommandType]'StoredProcedure'
#$Cmd.Parameters.Add("@TargetTableName", $tableName)
$SQLAdapter = New-Object System.Data.Sqlclient.SqlDataAdapter
$SqlAdapter.SelectCommand = $Cmd
$rs = New-Object System.Data.DataSet
$SqlAdapter.Fill($rs)
Return $rs.Tables[0] | Format-Table
$Con
n.Close()
}
When I try to Run this function it returns the result like below
fkeyid : Action
fkeycol : ActionTypeID
fkeynull : False
rkeyid : ActionType
rkeycol : ID
nkcol : Name
alias :
nullable : False
fkOrder : 1
fkeyid : Action
fkeycol : DefaultTimeTrackingTaskID
fkeynull : True
rkeyid : TimeTrackingTask
rkeycol : ID
nkcol : Name
alias :
nullable : True
fkOrder : 1
I'm looking for a result like
fkeyid fkeycol fkeynull rkeyid rkeycol nkcol alias nullable fkOrder
------ ------- -------- ------ ------- ----- ----- -------- -------
Action Actio... False Actio... ID Name False 1
Action Defau... True TimeT... ID Name True 1
Action Proce... False Process ID Proce... Proce... False 1
Action TimeT... True TimeT... ID Name True 1
I can achieve that using Format-Table . but cannot save the resultset to an Array. I want to be able to save it to an Array and work on it. Any help is much appreciated.
Thanks.