Reputation: 1591
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
Upvotes: 2
Views: 290
Reputation: 59001
You could use the Foreach-Object
cmdlet for that:
Get-AzureSqlDatabaseServer | Foreach-Object {
$db = $_ | Get-AzureSqlDatabase
$db | Add-Member NoteProperty -name ServerName -value $_.ServerName
$db
}
Upvotes: 1
Reputation: 174900
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}}
Upvotes: 3