Forum Discussion
youssefch
Jun 29, 2019Copper Contributor
Add-PnPFile : Access denied. You do not have permission to perform this action or access this resour
I am trying to upload a file (actually copy a file from a local machine) to folder in OneDrive for Business
$UserName="user@domain"
$pwd ="StrongPassword"
$SiteUrl = ""
$encpassword = convertto-securestring -String $pwd -AsPlainText -Force
$cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $username, $encpassword
Connect-PnPOnline -Url $SiteUrl -Credentials $cred
echo "connected"
Add-PnPFile -Path '.\localFileName.docx' -Folder 'Documents'
I get : Add-PnPFile : Access denied. You do not have permission to perform this action or access this resource.
I'am global admin in O365 and in Azure Portal
- AkshaySolanki1994Brass ContributorDid you get any workaround for it as I get the same error even though being an owner of the site
- Toby StathamBrass Contributor
youssefch You will still need to add yourself as a Site Collection Administrator to the user's Personal Site
Connect to the tenant admin site and add the user as a site collection admin
Set-SPOUser -Site $PersonalSiteUrl -LoginName $AccountRunningScript -IsSiteCollectionAdmin $true
Then you should be able to connect and add the file. You will want to remove the user afterwards