Getting all SharePoint metadata fields

MVP

Hi all,

 

I'm looking to create a CSV export of all items on a SharePoint site.  This includes the basic metadata fields (name, created date, modified date, etc.) as well as metadata fields added to either the list/library or associated with the item's content type.

 

I was able to get all the data and store it in a JSON structure. 

 

 {
        "ContentTypeId":  "0x01010...",
        "FileLeafRef":  "Sample File A - Test AAAA.docx",
        "File_x0020_Type":  "docx",
        "HTML_x0020_File_x0020_Type":  null,
        "ComplianceAssetId":  null,
        "Title":  "Sample File",
        "TemplateUrl":  null,
        "LegacyPath":  null,
        "TaxGroup":  [
                         "Dept1",
                         "Dept2"
                     ],
        "TaxLookup":  [
                            {
                                "LookupId":  2,
                                "LookupValue":  "YT8zNQN...RNQ==",
                                "TypeId":  "{GUID}"
                            }
                        ],
        "AdvisoryCategory":  [
                                 "International",
                                 "Canada"
                             ],
    }

 

What I need to do now is get any property that a list or object and get the child properties for it (e.g. TaxGroup, TaxLookup, AdvisoryCategory.  Can someone provide some input on how to get it?

3 Replies

@Haniel Croitoru 

I Hope this can help.

So the challenge is nether the property is known and even not able to call it as its totally unknown

I used to loop through all the object and get the Member type and base on the result do the requirement. 

this is a simple sample, but I hope it give an idea.

$MyJson=Get-Content -Path C:\PortQryV2\1.txt -Raw | ConvertFrom-Json
$Objects=$MyJson | gm -MemberType NoteProperty | where {$_.Definition -like "*system.Object*"}
$Objects.ForEach{
Write-Host "The Property " -NoNewline
Write-Host $($_.name) -ForegroundColor Green -NoNewline
Write-Host " has the following properties"
$MyJson.($_.name)
Write-Host ""

}

@Haniel Croitoru 

Hi

Did the proposed solution worked for you or you manage to get a better one

if you manage to get a better one, please share it with us.

If the propose solution helped you , Please click on Best response 

Thanks

 

@farismalaeb 

 

Thanks for your reply.  Actually, I needed to get each dynamic member, check its type, and then act accordingly.  Here's a snippet of what I did.

 

            $members = Get-Member -InputObject $fields -MemberType NoteProperty
            foreach ($mem in $members)
            {
                if ($null -ne $fields.($mem.Name))
                {
                    $type = $fields.($mem.Name).GetType().BaseType.Name
                    # if the item is an array, concatenate the values with a |
                    if ($fields.($mem.Name).GetType().BaseType.Name -eq "Array")
                    {
                        $fields.($mem.Name) = $fields.($mem.Name) -join "|"
                    }
                    elseif ($fields.($mem.Name).GetType().BaseType.Name -eq "Object")
                    {
                        # if it's a term, then add the value and term GUID
                        $internalObject = New-Object PSObject $fields.($mem.Name)
                        if (-not [String]::IsNullOrEmpty($internalObject))
                        {

                            if ($internalObject -like "*TermGuid*")
                            {
                                $fields.($mem.Name) = $internalObject.Label + "|" + $internalObject.TermGuid
                            }

                        }
                    }
                }
                
            }

 

 

Regards,

-Haniel