Forum Discussion

Eswar2015's avatar
Eswar2015
Copper Contributor
Jul 09, 2019

Cant delete file from SP online document library using Powershell.

Hi All,

 

I have the following requirement delete a file from SP Document library fom all folders & Subfolders.

 

Here is my script (delete file.txt).

Want to delete a file by name, 

 

Kindly suggest where, I am going wrong.

 

Thanks,

Eswar T

 

 

 

Thanks,

Eswar

  • Eswar2015 I'm having a hard time seeing in your script where your delete is happening. But based on the error, you are getting the document title and trying to delete that. You need to get a reference to the file object using the Title, and delete the file object. 

    • Eswar2015's avatar
      Eswar2015
      Copper Contributor

      Beau Cameron ,

       

      Greetings , this is what i am trying based on title of the column in this case : Name I am trying to delete the file.

       

      The script runs with no errors , but i dont get the file deleted.

       

      Please find the below lines of code , I made changes to & kindly suggest.

       

      if($fname["Name"] -eq "notfoundchanged5.34.xslx")
      {
      $Ctx.load($Folder.files)
              $fname.delete()

      Write-host -f Magenta $fname
              $Ctx.ExecuteQuery()

      }

       

      Name is the name of the column value in the document library , I am checking with and using delete to delete the file.

       

      Regards,

      Eswar.

Resources