Created
January 18, 2019 07:24
-
-
Save OlafD/9305d2d04fd8db8ef022807faf0480e7 to your computer and use it in GitHub Desktop.
For a list given by its name and for a view in this list given by its name, get the zero-based position of the field given by its internal name. When the field does not exist in the view, the result 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]$Listname, | |
[string]$Viewname, | |
[string]$Fieldname | |
) | |
$result = -1 | |
$currentPosition = -1 | |
$view = Get-PnPView -List $Listname -Identity $Viewname -Includes ViewFields | |
if ($view -ne $null) | |
{ | |
$viewFields = $view.ViewFields | |
foreach ($viewField in $viewFields) | |
{ | |
$currentPosition++ | |
if ($viewField -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