Skip to content

Instantly share code, notes, and snippets.

@OlafD
Created January 18, 2019 07:24
Show Gist options
  • Save OlafD/9305d2d04fd8db8ef022807faf0480e7 to your computer and use it in GitHub Desktop.
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.
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