Get-PnPField on the web/site level instead on the list level. is this possible?

john john 986 Reputation points
2023-02-03T20:47:55.5233333+00:00

I have this PnP Powershell script to get a field on the list level and hide it from the New form:-

Connect-PnPOnline <tenant-site-url>

$ctx = Get-PnPContext
$field = Get-PnPField -Identity <field-name> -List <list-name>

$field.SetShowInNewForm($false)
$field.Update()
$ctx.ExecuteQuery()

but how i can get the field on the web/site level, instead on the list level. so i can set this property for the field on the web/site level and get it applied to all the lists?

Thanks

SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
11,204 questions
SharePoint Development
SharePoint Development
SharePoint: A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.Development: The process of researching, productizing, and refining new or existing technologies.
3,290 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. RaytheonXie_MSFT 38,956 Reputation points Microsoft Vendor
    2023-02-06T01:45:51.2+00:00

    Hi @john john ,

    There is no such function to get a field on the web/site level. You can get a collection of lists in the site, then set the field in a loop. Please refer to the following commend

    $Lists = Get-PnPList
    foreach($List in $Lists){
    $field = Get-PnPField -Identity <field-name> -List <list-name> $field.SetShowInNewForm($false) $field.Update() $ctx.ExecuteQuery()
    }
    

    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.