powershell - Remove ContentType from list Office 365 -


i want remove content-type list in office 365 using powershell. found code $doclibrary null.

$lookforlist = "document" $stringctremove = "your content type"         $doclibrary = $_.lists[$lookforlist]       if($doclibrary -ne $null)     {         $cttoremove = $doclibrary.contenttypes[$stringctremove]         write-host "removing content type" $cttoremove.name "from list" $doclibrary.title         $doclibrary.contenttypes.delete($cttoremove.id)         $doclibrary.update()     }     else     {         write-host "the list" $lookforlist "does not exist in site" $_.title     } } 

solution:

function removebannersct ($web) {     $listname = "banners"     $list = $context.web.lists.getbytitle($listname)     $context.load($list)     $context.executequery()     $stringctremove = "picture"          if($list -ne $null)         {             $lcontenttypes = $list.contenttypes             $context.load($lcontenttypes)             $context.executequery()             foreach($cts in $lcontenttypes)             {                 if($cts.name -eq $stringctremove)                 {                     $list.contenttypes.getbyid($cts.id).deleteobject()                     $list.update()                     write-host "content-type removed"                 }             }         }         else         {             write-host "the list" $listname "does not exist in site"         } } 

please, can me? i'm crazy!

thanks in advance.

here go solution, there 2 methods 1 remove content type id , other content type name.

function set-sporemovecontenttypebyname { [cmdletbinding()]     param (         [microsoft.sharepoint.client.clientcontext]$ctx,          [string]$splist,         [string]$ctname     )      $web = $ctx.web     $list = $ctx.web.lists.getbytitle($splist)     $cnttypecoll =$list.contenttypes     $ctx.load($web)      $ctx.load($list)     $ctx.load($cnttypecoll)     $ctx.executequery()        foreach($ct in $cnttypecoll)     {      if($ct.name -eq $ctname)         {         $ct.deleteobject()         break;         }     }      $ctx.executequery()  }   function set-sporemovecontenttypebyid { [cmdletbinding()]     param (         [microsoft.sharepoint.client.clientcontext]$ctx,          [string]$splist,         [string]$ctid     )      $web = $ctx.web     $list = $ctx.web.lists.getbytitle($splist)     $cnttypecoll =$list.contenttypes     $ctx.load($web)      $ctx.load($list)     $ctx.load($cnttypecoll)     $ctx.executequery()    write-host "required content type id :" $ctid      foreach($ct in $cnttypecoll)     {     write-host "intertaed id " $ct.id       if($ct.id.tostring() -eq $ctid)         {         $ct.deleteobject()         break;         }     }      $ctx.executequery()  }  

cheers, kiran


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -

How to provide Authorization & Authentication using Asp.net, C#? -