sharepoint - Delete a wiki page with powershell -


i need code. first tried create new wiki page in sharepoint 2013 , worked perfectly. i'm trying delete wiki page , doesn't work well.

my code:

add-type –path "c:\users\benutzername\appdata\local\apps\officedevpnp.powershell.v15.commands\modules\officedevpnp.powershell.v15.commands\microsoft.sharepoint.client.dll"   add-type –path "c:\users\benutzername\appdata\local\apps\officedevpnp.powershell.v15.commands\modules\officedevpnp.powershell.v15.commands\microsoft.sharepoint.client.runtime.dll"   function delete-wikipage ([microsoft.sharepoint.client.clientcontext]$context, [string]$wikilibrarytitle,[string]$pagename) {     $wikilibrary = $context.web.lists.getbytitle($wikilibrarytitle)     $context.load($wikilibrary.rootfolder.files)     $context.executequery()      $wikipage = $wikilibrary.rootfolder.files | {$_.name -eq $pagename}     $context.load($wikipage)     $context.deleteobject() } $url = "hhtps://sharepoint.com" $context = new-object microsoft.sharepoint.client.clientcontext($url) $pagename = "testlauf.aspx" delete-wikipage -context $context -wikilibrarytitle "testwiki" -pagename $pagename 

i got error message deleteobject() method didn't find how can fix that:

error when calling method [microsoft.sharepoint.client.clientcontext] no method found name "deleteobject". in c:\users\benutzername\desktop\projektarbeit_wiki\powershell\delete_wikipage.ps1:12 zeichen:5 +     $context.deleteobject() +     ~~~~~~~~~~~~~~~~~~~~~~~     + categoryinfo          : invalidoperation: (:) [], runtimeexception     + fullyqualifiederrorid : methodnotfound 

i can work methods add-types. can me this?

you use csom in powershell. (you load csom dll ). should search information sharpoint csom.

to answer question, use : deleteobject() on object : context. methode doesn't exist on context object. methode exist on file.

si should try :

$wikipage = $wikilibrary.rootfolder.files | {$_.name -eq $pagename} $context.load($wikipage) $context.executequery() //get item, not sure needed $wikipage.deleteobject() $context.executequery() 

personal note : should use caml query retrieve wikipage, not this: $wikipage = $wikilibrary.rootfolder.files | {$_.name -eq $pagename} kind of query have bad performance, , can raise exception list threshold


Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -