Using Custom PS Objects to Quickly Filter Data from Custom PS Modules

Many times when working with Powershell Modules, I’m presented with an object that contains data that I want, but it’s embedded inside nested hash tables, or isn’t quite storing the data in a way that’s useful for me to work with.

For example, let’s take the output of a function from Rubrik’s Powershell Module – “Get-RubrikSLA“. This command will output all the information about various backup policies, but doesn’t quite present it in a usable format for me (Say to output to a CSV file).

I’m interested in the frequencies of the backups, the name of the SLA Domain, and not much else. If we try to export the data right now using Select-Object we will see that the frequencies are inside an embedded hash table. When running “Export-CSV”, we’ll just be presented with this in our row –

Really, the data we are interested in is inside another has table called Daily. Drilling down, we can see that 'Daily' contains a the key;value pair Frequency,Retetention

The way to work around this limitation is to create a script that utilizes custom PS objects. This script will loop over the object we examined above, and push the data we want from each nested hash table, into a custom object called $slaOBjRecord . This object will then be added to an array, $sla_report_array.

Using this technique we end up with a result that looks like the table below, and can be used with export-csv without any issue.

Leave a Comment

Your email address will not be published. Required fields are marked *