Is it possible to have custom datatype in powershell?
I would like to have a (structured) variable like below. Following thing is not syntactically correct.I just want to club following three variables.
Variable Databasedetails {
string DatabaseName
string TableName
string[] columnNames
}
If Powershell has provision to do it then i can have single variable array which can help me to write queries easily.
$Databasedetails = { "DataBaseName=DB-someX","TableName=TableX"," (ColumnNames={"Col1","col2"}"
"DataBaseName=DB-someY","TableName=TableY"," (ColumnNames={"Col2","colN"}"
}
Foreach ($DBdetails in $DataBaseDetails)
{
$query= "SELECT [$DBdetails.$columnName] FROM [$DBdetails$DatabaseName].[dbo].[$DBdetails.$TableName]"
invoke-sqlcmd -query $query -ServerInstance $srvInstance"
}
Is there any way to create structured variable and i can create array of that and process?
You will want to look into either Add-Member or Add-Type, the later being only in Powershell 2.0.
or with Add-Type