I’ve looked through the questions asked on this topic, including one I asked before, but none help me with this particular issue.
I have two arrays, one has database properties, the other has data file properties. Some databases have more than one datafile. How can I combine the two arrays allowing for occasions when a database has an unknown amount of datafiles?
I’m exporting this to an excel spreadsheet, and I’m hoping that each database has 1 line…there maybe columns that have null values for other databases, that’s ok. The common value in the two arrays is database name.
Here’s my two arrays.
$Db = $_
$Databases += [PSCustomObject][ORDERED]@{
Name = $Db.Name
CreateDate = $Db.CreateDate
Owner = $Db.Owner
RecoveryModel = $Db.RecoveryModel
EncryptionEnabled = $Db.EncryptionEnabled
BrokerEnabled = $Db.DatabaseOptions.BrokerEnabled
PageVerify = $Db.DatabaseOptions.PageVerify
TargetRecoveryTime = $Db.TargetRecoveryTime
DatabaseSize = [math]::Round($Db.Size,0)
DataSpaceUsage = [math]::Round(($Db.DataSpaceUsage * 1024) / 1MB,0)
IndexSpaceUsage = [math]::Round(($Db.IndexSpaceUsage * 1024) / 1MB,0)
SpaceAvailable = [math]::Round(($Db.SpaceAvailable * 1024) / 1MB,0)
LastBackupDate = $Db.LastBackupDate
LastGoodCheckDbTime = $Db.LastGoodCheckDbTime
PrimaryFilePath = $Db.PrimaryFilePath
LogFileName = $Db.LogFiles.Name
LogFilePath = $Db.LogFiles.FileName
LogFileSize = [math]::Round(($Db.LogFiles.Size * 1024) / 1MB,0)
LogFileUsedSpace = [math]::Round(($Db.LogFiles.UsedSpace * 1024) / 1MB,0)
LogVolumeFreeSpace = [math]::Round(($Db.LogFiles.VolumeFreeSpace * 1024) / 1MB,0)
LogFileGrowth = $Db.LogFiles.Growth
LogFileGrowthType = $Db.LogFiles.GrowthType
}
…and
$DataFiles = @()
$Db.FileGroups | %{
$_.Files | %{
$DataFiles += [PSCustomObject][ORDERED]@{
Name = $_.Name
FileName = $_.FileName
Size = $_.Size
Growth = $_.Growth
GrowthType = $_.GrowthType
MaxSize = $_.MaxSize
UsedSpace = $_.UsedSpace
VolumeFreeSpace = $_.VolumeFreeSpace
FileGroup = $_.Parent.Name
}
}
}