Skip to content

Instantly share code, notes, and snippets.

@OlafD
Created January 18, 2019 07:21
Show Gist options
  • Save OlafD/5dd334605027cb21a8216b189c7bd4a4 to your computer and use it in GitHub Desktop.
Save OlafD/5dd334605027cb21a8216b189c7bd4a4 to your computer and use it in GitHub Desktop.
Get the zero-based position of a field, given by its internal name in a content type given by its name. When the field does not exist in the content type, the return value is -1.
param (
[string]$ContentTypeName,
[string]$FieldName
)
$result = -1
$currentPosition = -1
$ct = Get-PnPContentType -Identity $ContentTypeName
if ($ct -ne $null)
{
$fieldLinks = Get-PnPProperty -ClientObject $ct -Property FieldLinks
foreach ($fieldLink in $fieldLinks)
{
$currentPosition++
if ($fieldLink.Name -eq $FieldName)
{
$result = $currentPosition
break
}
}
}
Write-Output $result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment