Delete Specific file in Sharepoint Library folder

%3CLINGO-SUB%20id%3D%22lingo-sub-1282370%22%20slang%3D%22en-US%22%3EDelete%20Specific%20file%20in%20Sharepoint%20Library%20folder%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1282370%22%20slang%3D%22en-US%22%3E%3CDIV%3E%3CDIV%3E%3CSPAN%3EDear%20All%2C%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3EI'm%20looking%20for%20some%20help%20on%20following%20commands.%20I%20tried%20to%20delete%20on%20files%20which%20is%20in%20Documents%20Library.%20Im%20using%20below%20commands.%26nbsp%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%3CEM%3E%3CSTRONG%3E%24siteurl%3D%22%3CA%20href%3D%22https%3A%2F%2Fdomain.sharepoint.com%2Fsites%2Ftest%2FShared%26nbsp%3BDocuments%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fdomain.sharepoint.com%2Fsites%2Ftest%2FShared%26nbsp%3BDocuments%3C%2FA%3E%22%3C%2FSTRONG%3E%3C%2FEM%3E%3C%2FDIV%3E%3CDIV%3E%3CEM%3E%3CSTRONG%3EConnect-PnPOnline%26nbsp%3B-Url%26nbsp%3B%24siteurl%3C%2FSTRONG%3E%3C%2FEM%3E%3C%2FDIV%3E%3CDIV%3E%3CEM%3E%3CSTRONG%3ERemove-PnPFile%26nbsp%3B-ServerRelativeUrl%26nbsp%3B%22%2Fsites%2FTest%2FSharedDocuments%2FCreate.csv%22%3C%2FSTRONG%3E%3C%2FEM%3E%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3EBut%20when%20it%20run%20it%20gives%20below%20error%20%3A%26nbsp%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CEM%3E%3CSTRONG%3ERemove-PnPFile%20%3A%20The%20remote%20server%20returned%20an%20error%3A%20(403)%20Forbidden.%3CBR%20%2F%3EAt%20line%3A1%20char%3A1%3CBR%20%2F%3E%2B%20Remove-PnPFile%20-ServerRelativeUrl%20%22%2Fsites%2FTest%2FShared%20Documents%2FC%3C%2FSTRONG%3E%3C%2FEM%3E%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3EI%20tried%20several%20suggestions%20on%20some%20blogs%20for%20past%20few%20days.%20Still%20I%20couldn't%20figure%20out%20what%20is%20the%20issue.%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3ECould%20you%20please%20some%20one%20help%20me%20on%20this.%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3EThank%20you.%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3C%2FDIV%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1282370%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3ESharePoint%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1282387%22%20slang%3D%22en-US%22%3ERe%3A%20Delete%20Specific%20file%20in%20Sharepoint%20Library%20folder%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1282387%22%20slang%3D%22en-US%22%3EHi%2C%3CBR%20%2F%3EBased%20on%20the%20error%2C%20it%20clearly%20shows%20the%20account%20you%20are%20running%20the%20PowerShell%20doesn't%20have%20access%20rights%20to%20delete%20the%20file.%20It%20can%20be%20due%20to%20following%3CBR%20%2F%3E1.%20Maybe%20the%20file%20is%20checked-out%20by%20the%20other%20user%3CBR%20%2F%3E2.%20Maybe%20the%20delete%20action%20is%20blocked%20for%20the%20user%3CBR%20%2F%3EYou%20can%20check%20the%20above%20scenario%20and%20try%20deleting%20again%20or%20you%20can%20use%20-Force%20in%20your%20command.%3CBR%20%2F%3E%3CBR%20%2F%3EHope%20it%20helps%2C%20please%20like%20it%20or%20mark%20it%20as%20a%20solution%20if%20it%20resolves%20ur%20clarification%20or%20issue%3CBR%20%2F%3E-Sudharsan%20K...%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1282460%22%20slang%3D%22en-US%22%3ERe%3A%20Delete%20Specific%20file%20in%20Sharepoint%20Library%20folder%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1282460%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F144422%22%20target%3D%22_blank%22%3E%40Sudharsan%20K%3C%2FA%3E%26nbsp%3BThank%20you%20for%20your%20valuable%20inputs.%20The%20user%20has%20owner%20permission%20for%20the%20site.%26nbsp%3B%3C%2FP%3E%3CP%3EI%20will%20check%20as%20you%20described%20and%20share%20the%20output.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%20again.%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1282623%22%20slang%3D%22en-US%22%3ERe%3A%20Delete%20Specific%20file%20in%20Sharepoint%20Library%20folder%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1282623%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F144422%22%20target%3D%22_blank%22%3E%40Sudharsan%20K%3C%2FA%3E%26nbsp%3BI%20checked%20with%20mentioned%20suggestions.%20Still%20I%20getting%20the%20same%20error.%20I%20Can%20delete%20the%20file%20without%20issues%20from%20GUI%20using%20the%20same%20user.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAlso%20the%20-Force%20also%20giving%20same%20error.%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E
Highlighted
New Contributor
Dear All,
 
I'm looking for some help on following commands. I tried to delete on files which is in Documents Library. Im using below commands. 
 
Connect-PnPOnline -Url $siteurl
Remove-PnPFile -ServerRelativeUrl "/sites/Test/SharedDocuments/Create.csv"
 
But when it run it gives below error : 
Remove-PnPFile : The remote server returned an error: (403) Forbidden.
At line:1 char:1
+ Remove-PnPFile -ServerRelativeUrl "/sites/Test/Shared Documents/C
 
I tried several suggestions on some blogs for past few days. Still I couldn't figure out what is the issue.
Could you please some one help me on this.
Thank you.
 
 
3 Replies
Highlighted
Hi,
Based on the error, it clearly shows the account you are running the PowerShell doesn't have access rights to delete the file. It can be due to following
1. Maybe the file is checked-out by the other user
2. Maybe the delete action is blocked for the user
You can check the above scenario and try deleting again or you can use -Force in your command.

Hope it helps, please like it or mark it as a solution if it resolves ur clarification or issue
-Sudharsan K...
Highlighted

@Sudharsan K Thank you for your valuable inputs. The user has owner permission for the site. 

I will check as you described and share the output.

 

Thanks again. 

Highlighted

@Sudharsan K I checked with mentioned suggestions. Still I getting the same error. I Can delete the file without issues from GUI using the same user. 

 

Also the -Force also giving same error.