Forum Discussion
Haniel Croitoru
Feb 08, 2021Learn Expert
Getting all SharePoint metadata fields
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...
farismalaeb
Feb 08, 2021Steel Contributor
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 CroitoruFeb 10, 2021Learn Expert
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