powershellonenote

Powershell : Object within Object - extract Property values (and export to CSV) - OneNoteUtilitiesGraph


Still fairly new to PowerShell and trying to get a list of all my OneNote pages within a given Section and Notebook...and into a CSV. I'm nearly there, but the final bits are eluding me. I've tried a few things:

I'm using https://github.com/wightsci/OneNoteUtilitiesGraph

# This my 'ffmpeg etc' Section. Get its Page(s) info:
$sPages = Get-MgUserOnenoteSectionPage -OnenoteSectionId "0-nnnn" -UserId "bbbb@yyyy.com"

# What do we have available to us?
$sPages | Get-Member

Shows (subset):

Title                Property              string Title {get;set;}
CreatedDateTime      Property              System.Nullable[datetime] CreatedDateTime {get;set;}
ParentSection        Property              Microsoft.Graph.PowerShell.Models.IMicrosoftGraphOnenoteSection ParentSection {get;set;}

So the last one is Object within an Object?? Anyway, picking some at random and checking some values

$sPages[3].Title
Cut a video (lossless) with no re-encoding

$sPages[3].ParentSection.DisplayName
ffmpeg etc

But

Foreach($s in $sPages) { $s | select Title, CreatedDateTime,ParentSection.DisplayName }

Has no value for ParentSection.DisplayName:

Title                                                           CreatedDateTime        ParentSection.DisplayName
-----                                                           ---------------        -------------------------
Powershell (ffmpeg) to split media file by times.csv            28/10/2020 10:01:02 AM
Series of numbered images to a video                            6/04/2019 9:35:33 PM
Fuji camera - Timelapse (of cool change, clouds)                6/04/2019 9:36:27 PM

What's the correct way to do this, particularly if I want to end up saving these 3 property values to a CSV file? Thanks.


Solution

  • You need a calculated property for this to get the Displayname of the ParentSection as property of the same object(s)

    Try:

    foreach($s in $sPages) { 
        $s | Select-Object Title, CreatedDateTime,
                           @{Name = 'ParentSection'; Expression = { $_.ParentSection.DisplayName }}
    }