Shiju Samuel Shiju Samuel - 1 year ago 104
PowerShell Question

Access PowerShell pipeline properties

Is there a way to expose the pipeline properties of the previous command in the output of the next command. Below will loop through each SQL Server and get databases. The output only gives me the database name but I am looking for a way to get the Server Name also in the output.

Get-AzureSqlDatabaseServer | Get-AzureSqlDatabase

Answer Source

You can combine Select-Object with the -PipelineVariable common parameter (pv) of a previous command:

Get-AzureSqlDatabaseServer -pv Server |Get-AzureSqlDatabase |Select-Object *,@{Label='ServerName';Expression={$Server.ServerName}}