Rename-pnpFile gives me access denied with admin rights

Copper Contributor

Hello!

I have problems renaming my files.

I'm using these commands:

#this is one command i tried
connect-pnponline -url "https://contoso.sharepoint.com/sites/Clients" -interactive -validateconnection
$file = Get-PnPFile -Url "/sites/Clients/folder/subfolder/IT_testi_password.txt"
Rename-PnPFile -SiteRelativeUrl $file -TargetFileName "renamedfile.txt" -Force -Verbose

# this is another
connect-pnponline -url "https://contoso.sharepoint.com/sites/Clients" -interactive -validateconnection
Rename-PnPFile -SiteRelativeUrl "/sites/Clients/folder/subfolder/IT_testi_password.txt" -TargetFileName "renamed.txt" -Force -Verbose

I tried those commands too with overwrite but I only get access denied (I dont know what is checking to say me that because i can put everything in the source and it says me same )

 

the error:

#I'm putting this error to show that i can put anything i want

Line |
   4 |  Rename-PnPFile -SiteRelativeUrl "asrfeqrew" -TargetFileName "workingc …
     |  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | Access denied.
PS /Users/user> 

#and this one is a common one
Rename-PnPFile: /Users/user/Desktop/project/Scripts/Untitled-1.ps1:4:1
Line |
   4 |  Rename-PnPFile -SiteRelativeUrl "/sites/Clients/folder/subfolder/IT_testi_password.txt" -T …
     |  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | Access denied.

I'm using visual studio with a mac and have Sharepoint administrator right, also i can rename the same file via web.

 

Can someone help me with this problem?

 

 

4 Replies

Hi @afierro97 

 

I believe is not a permission issue. Use ServerRelativeUrl instead of SiteRelativeUrl and put the url of the file instead of the $file object.

Rename-PnPFile -ServerRelativeUrl  "/sites/MySite/Shared Documents/myfolder/myfile.txt" -TargetFileName "renamedfile.txt" -Force -Verbose

 

Hi Luis,
I've tried that and gave me the same error.
Thanks for your help!
I believe too that is not a permission issue but i dont know what to do or how to debbug the error

Hi @afierro97 

Just to make it clear, in your example "/sites/Clients/folder/subfolder/" note that folder should be the library url and then your folders

Yes, i've changed the names of the path for confidenciality but i've built the path like this:
"/sites/<name of the site>/<name of the library>/<folder>/<File.txt>"