Advertisement
Guest User

Untitled

a guest
Apr 28th, 2015
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1. function SetCustomForms-InContentType()
  2. {
  3. param(
  4. [Parameter(Mandatory=$true)][string]$url,
  5. [Parameter(Mandatory=$false)][System.Net.NetworkCredential]$credentials,
  6. [Parameter(Mandatory=$true)][string]$ContentTypeName
  7. )
  8.  
  9. begin{
  10. try
  11. {
  12. #get Client Object
  13. $Context = New-Object Microsoft.SharePoint.Client.ClientContext($url)
  14. $Context.Credentials = $Credentials
  15.  
  16. #Load web object
  17. $web = $Context.Web
  18. $site = $context.Site
  19. $Context.Load($web)
  20. $Context.Load($site)
  21. $Context.ExecuteQuery()
  22.  
  23. }
  24. catch
  25. {
  26. Write-Host "Error while getting context. Error -->> " + $_.Exception.Message -ForegroundColor Red
  27. }
  28. }
  29. process{
  30. try
  31. {
  32.  
  33. $contentTypes = $Context.Site.RootWeb.ContentTypes
  34. $Context.Load($contentTypes)
  35. $Context.ExecuteQuery()
  36. $contentType = $contentTypes | Where {$_.Name -eq $ContentTypeName}
  37.  
  38. $contentType.EditFormUrl = "Your Custom URL"
  39. $contentType.NewFormUrl = "Your Custom URL"
  40. $contentType.DisplayFormUrl = "Your Custom URL"
  41.  
  42.  
  43. $contentType.Update()
  44. $Context.Load($contentType)
  45. $Context.ExecuteQuery()
  46. }
  47. catch
  48. {
  49. Write-Host ("Error -->> " + $_.Exception.Message) -ForegroundColor Red
  50. }
  51. }
  52. end{
  53. $Context.Dispose()
  54. }
  55. }
  56.  
  57.  
  58. $credentials = Get-Credential
  59. $Url = 'http://YourSite'
  60.  
  61. SetCustomForms-InContentType $Url $credentials "Your Content Type Name"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement