Created
January 18, 2019 07:21
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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