0

I am using the CSOM for PowerShell to get all the default forms(new/display/edit) used by the list in SharePoint online site. Below is the code snippet for the same.

$NewFormUrl = $List.DefaultNewFormUrl
$DisplayFormUrl = $List.DefaultDisplayFormUrl
$EditFormUrl = $List.DefaultEditFormUrl

These values are returned as blank for any lists inside the site. I am able to fetch other list properties except these three property values.

How can I get the default forms?

2 Answers 2

0

@Adam has provided a good method, and you can take a referecne of below csom powerhsell script:

Add-Type -Path 'C:\Program Files\Common Files\microsoft shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll'

#Mysite URL
$site = 'https://abc.sharepoint.com/sites/sbdev'

#Admin User Principal Name
$admin = '[email protected]'

#Get Password as secure String
$password = ConvertTo-SecureString "xxxxxx" -AsPlainText -Force

#Get the Client Context and Bind the Site Collection
$context = New-Object Microsoft.SharePoint.Client.ClientContext($site)

#Authenticate
$credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($admin , $password)
$context.Credentials = $credentials

$list = $context.Web.Lists.GetByTitle('mm')

[string[]]$props = @("DefaultNewFormUrl","DefaultDisplayFormUrl","DefaultEditFormUrl")
$list.Retrieve($props)

$context.Load($list)
$context.ExecuteQuery()    

$List.DefaultNewFormUrl
$List.DefaultDisplayFormUrl
$List.DefaultEditFormUrl

Result:

enter image description here

BR


Not sure if below code meet the requirement,

#Get all forms
$context.Load($list.forms)
$context.ExecuteQuery()
$list.forms

# check CustomizedPageStatus
$f_form= $list.RootFolder.Files.GetByUrl($list.DefaultDisplayFormUrl)
$context.Load($f_form)
$context.ExecuteQuery()

$f_form.CustomizedPageStatus

got some tips from:

1
  • Thanks Adam! Can you tell me one thing, how to identify whether the form is a default out of the box form or a customized one? Aug 31, 2020 at 6:02
1

You need to include them in the context query so they will be initialized. By default not all properties of and object are initialized. I don't quite remember how to do include in plain PowerShell CSOM (I think it was not that easy).

For SharePoint Online I would suggest you to use PnP PowerShell which makes many things very easy, and always if something is still not available you may then use plain CSOM approach on the context.

So with PnP PowerShell you could do it like this:

Connect-PnPOnline -Url "YourSiteUrl"
$list = Get-PnPList -Identity "YourListName" -Includes DefaultDisplayFormUrl, DefaultEditFormUrl, DefaultNewFormUrl
$list.DefaultDisplayFormUrl
$list.DefaultEditFormUrl
$list.DefaultNewFormUrl

I tested this and the result is present below enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.