Apr 10 2018 02:42 AM
Hi
Get-PnPContentTypes only brings back a subset of all of the site columns in a contenttype.
So I have a loop so :-
$CTypes = Get-PnPContentType
foreach($contentType in $CTypes)
{
$fieldInUse = $contentType.FieldLinks | Where {$_Name -eq $columnInternalName }
if($fieldInUse -ne $null)
{
Write-Host "Found The Column in ContentType: " $contentType.Name -ForegroundColor DarkGreen
}
}
I get an error :-
An error occurred while enumerating through a collection: The collection has not been initialized. It has not been
requested or the request has not been executed. It may need to be explicitly requested..
At line:1 char:1
+ $contentType.FieldLinks
+ ~~~~~~~~~~~~~~~~~~~~~~~
How do I get FieldLinks loaded via Get-PnPContentType ?
Thanks
Nigel
May 06 2018 02:57 PM
Hi,
you need to load collections via the context, so something like:
$CTypes = Get-PnPContentType
foreach($contentType in $CTypes)
{
$ctx = Get-PnPContext
$ctx.Load($contentType.FieldLinks)
$ctx.ExecuteQuery()
$fieldInUse = $contentType.FieldLinks | Where {$_Name -eq $columnInternalName }
# etc.
Thanks
Nigel
May 09 2018 07:36 AM
Thanks Nigel