Combine Two Powershell Scripts

Hello,

I have two working queries that are somewhat related and would like to combine.

[pre]
$resourceGroup = “azure-rg”
$serverName = “azure-srv1”
$dbName = “azure01”

$params = @{
ResourceGroupName = $resourceGroup;
ServerName = $serverName;
DatabaseName = $dbName;
}

Get-AzSqlDatabaseRestorePoints @params | Select-Object ServerName, DatabaseName, Location, EarliestRestoreDate
[/pre]

…and the second:

[pre]
$resourceGroup = “azure-rg”
$serverName = “azure-srv1”

$params = @{
ResourceGroupName = $resourceGroup;
ServerName = $serverName;
}

Get-AzSqlDatabaseGeoBackup @params | Select-Object ServerName, DatabaseName, Edition, LastAvailableBackupDate
[/pre]

I’d like to combine the output from both to show:

ServerName, DatabaseName, Edition, LastAvailableBackupDate, Location, EarliestRestoreDate

Any help would be appreciated!

Frank

There are a few ways you could approach this. One is to build a completely custom object and just pull in each individual property. Given that you’re only adding two from one object to the other, though, it’s probably simpler to just add them in.

You can use Add-Member if you don’t mind chaining a couple calls there, but personally I prefer to use Select-Object for these scenarios.

That’s a nice take on it, but since there are several databases hosted on the server it’s pulling multiple values for ‘Edition’ and ‘LastAvailableBackupDate’.

Any idea how I can filter out the other values or return all of the databases in a formatted table?

You could use .Where{} to filter for the specific database you’re targeting, or look to see if the cmdlet has parameters to do that for you. :slight_smile: