Shiju Samuel Shiju Samuel - 1 year ago 125
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}}
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download