# Combine Two Powershell Scripts

**URL:** <https://forums.powershell.org/t/combine-two-powershell-scripts/12374>\
**Category:** PowerShell Help\
**Created:** [April 10, 2019, 9:25am UTC](https://forums.powershell.org/t/combine-two-powershell-scripts/12374 "2019-04-10T09:25:27Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![anelliaf](https://avatars.discourse-cdn.com/v4/letter/a/cab0a1/32.png) [@anelliaf](https://forums.powershell.org/u/anelliaf)\
**Post date:** [April 10, 2019, 9:25am UTC](https://forums.powershell.org/t/combine-two-powershell-scripts/12374/1 "2019-04-10T09:25:27Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ta11ow](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/ta11ow/32/131_2.png) [@ta11ow](https://forums.powershell.org/u/ta11ow)\
**Post date:** [April 10, 2019, 9:38am UTC](https://forums.powershell.org/t/combine-two-powershell-scripts/12374/2 "2019-04-10T09:38:19Z")

</div>

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.

> <https://gist.github.com/vexx32/96ce0ffe20eec8357b5860e251180803>

---

<div class="post-metadata">

**Author:** ![anelliaf](https://avatars.discourse-cdn.com/v4/letter/a/cab0a1/32.png) [@anelliaf](https://forums.powershell.org/u/anelliaf)\
**Post date:** [April 10, 2019, 11:12am UTC](https://forums.powershell.org/t/combine-two-powershell-scripts/12374/3 "2019-04-10T11:12:27Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![ta11ow](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/ta11ow/32/131_2.png) [@ta11ow](https://forums.powershell.org/u/ta11ow)\
**Post date:** [April 10, 2019, 1:12pm UTC](https://forums.powershell.org/t/combine-two-powershell-scripts/12374/4 "2019-04-10T13:12:07Z")

</div>

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. 🙂

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:33pm UTC](https://forums.powershell.org/t/combine-two-powershell-scripts/12374/5 "2024-05-16T20:33:02Z")

</div>

Closed on May 16, 2024, 8:33pm UTC


