Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function SetCustomForms-InContentType()
- {
- param(
- [Parameter(Mandatory=$true)][string]$url,
- [Parameter(Mandatory=$false)][System.Net.NetworkCredential]$credentials,
- [Parameter(Mandatory=$true)][string]$ContentTypeName
- )
- begin{
- try
- {
- #get Client Object
- $Context = New-Object Microsoft.SharePoint.Client.ClientContext($url)
- $Context.Credentials = $Credentials
- #Load web object
- $web = $Context.Web
- $site = $context.Site
- $Context.Load($web)
- $Context.Load($site)
- $Context.ExecuteQuery()
- }
- catch
- {
- Write-Host "Error while getting context. Error -->> " + $_.Exception.Message -ForegroundColor Red
- }
- }
- process{
- try
- {
- $contentTypes = $Context.Site.RootWeb.ContentTypes
- $Context.Load($contentTypes)
- $Context.ExecuteQuery()
- $contentType = $contentTypes | Where {$_.Name -eq $ContentTypeName}
- $contentType.EditFormUrl = "Your Custom URL"
- $contentType.NewFormUrl = "Your Custom URL"
- $contentType.DisplayFormUrl = "Your Custom URL"
- $contentType.Update()
- $Context.Load($contentType)
- $Context.ExecuteQuery()
- }
- catch
- {
- Write-Host ("Error -->> " + $_.Exception.Message) -ForegroundColor Red
- }
- }
- end{
- $Context.Dispose()
- }
- }
- $credentials = Get-Credential
- $Url = 'http://YourSite'
- SetCustomForms-InContentType $Url $credentials "Your Content Type Name"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement