merge xml or gzip

Feb 4, 2014 at 12:27 PM
Hi for various reasons (different firewalls etc.) i have to create multiple xml.gz copies for the same company with the SQLpowerdoc script. I would like to combine these results into one file before converting it into excel documentation so all SQL documentation for the same company is listed in one place. Can anyone please give me any suggestions. Sorry if this question was answered in another thread. I did not pick it up.
Coordinator
Feb 17, 2014 at 10:06 PM
Hi and thanks for checking out SQL Power Doc!

First the bad news - currently there is no way to merge multiple GZ files into a single output. Now the good news - I'm working on this because you're not the first person to ask for it!

I don't have a timeline on when I'll have this particular feature done (I work on this in my spare time), but I'll post here when it looks like I'm getting close to having it written.

--Kendal
Oct 30, 2014 at 2:19 PM
Hi Kendal,

I have the same needs as Eugenius77, have you had enough spare time to lay the code?

Thanks.
Coordinator
Nov 11, 2014 at 4:55 PM
I ran into a similar problem myself and while it's not baked into the SQL Power Doc code (yet) here's what I did to merge multiple inventory files into a single new file. Note there's no de-duping going on here so if an instance is in both files it will show up twice in the reports.

_Note: Make sure to update $BasePath and $ServerInventory before running!_
Import-Module -Name SqlServerInventory

<# Specify the base path and the paths to the inventories to merge #>
$BasePath = "Z:\Users\kenda_000\Documents\SQL Power Doc"

$ServerInventory = @(
    "$BasePath\SQL01\SQL Server Inventory - 2014-10-10-01-11.xml.gz",
    "$BasePath\SQL02\SQL Server Inventory - 2014-10-10-00-50.xml.gz",
    "$BasePath\SQL Server Inventory - 2014-10-10-00-28.xml.gz"
)

<# Import all inventories into a collection #>
$Inventory = Import-SqlServerInventoryFromGzClixml -Path $ServerInventory

<# Merge the collection of inventories into a single inventory object #>
$MergedInventory = New-Object -TypeName psobject -Property @{
    Service = $Inventory | ForEach-Object { $_.Service }
    Version = $Inventory | ForEach-Object { $_.Version }
    DatabaseServerScanSuccessCount = ($Inventory | Measure-Object -Property DatabaseServerScanSuccessCount -Sum).Sum
    StartDateUTC = $Inventory | ForEach-Object { $_.StartDateUTC }
    DatabaseServerScanFailCount = ($Inventory | Measure-Object -Property DatabaseServerScanFailCount -Sum).Sum
    DatabaseServer = $Inventory | ForEach-Object { $_.DatabaseServer }
    EndDateUTC = $Inventory | ForEach-Object { $_.StartDateUTC }
    WindowsInventory = $Inventory | ForEach-Object { $_.WindowsInventory }
    DatabaseServerScanCount = ($Inventory | Measure-Object -Property DatabaseServerScanCount -Sum).Sum
}

<# Create the new inventory filename #>
$CliXmlPath = (Join-Path -Path $BasePath -ChildPath $('SQL Server Inventory - {0:yyyy-MM-dd-HH-mm}.xml.gz' -f $(Get-Date)))

<# Write the merged inventory to disk #>
Export-SqlServerInventoryToGzClixml -SqlServerInventory $MergedInventory -Path $CliXmlPath

Remove-Module -Name SqlServerInventory
Remove-Variable -Name BasePath, ServerInventory, Inventory, MergedInventory, CliXmlPath
Jan 19, 2015 at 9:51 AM
Hi Kendal, thanks for this, I played around with this script you posted. I am able to merge SQL inventories but when I get to the Windows inventory I am getting the following error :
ForEach-Object : Array assignment failed because index '1,0' was out of range.
At C:\Users\eugene\Documents\WindowsPowerShell\Modules\WindowsInventory\WindowsInventory.psm1:914 char:46

I appreciate any suggestions you have for this please, many thanks
Eugene van den Bergh
Coordinator
Feb 20, 2015 at 2:48 PM
Does each file that you're trying to merge have a Windows inventory in it? It almost sounds like one file does not.
Feb 23, 2015 at 10:15 AM
OK that makes sense I will check thanks


Sent by Outlook for Android



On Fri, Feb 20, 2015 at 6:48 AM -0800, "kendalvandyke" <[email removed]> wrote:

From: kendalvandyke

Does each file that you're trying to merge have a Windows inventory in it? It almost sounds like one file does not.