Replies: 5 comments 3 replies
-
Your TargetUrl is a relative path. It will need an absolute path if you want to move it to another site, so it probably tries to move it to a non-existent subsite, which somewhat explains the error (errors in SharePoint are usually confusing and vague):
Try It is also mentioned in example:
|
Beta Was this translation helpful? Give feedback.
-
Thank you. If I understand correctly, you have added a leading '/' in front of the $DestinationFolder path. I appreciate that note and tried this syntax based on the example in the documentation, but (retried it again just now) I got this:
That seemed to be some sort of pathing error and so I tried it without the '/' and got access denied... but it sounded like without the '/' it was maybe at least finding the correct path? |
Beta Was this translation helpful? Give feedback.
-
If you read the examples carefully here you will notice that you need "/" in front (absolute URL) if you want to move to another site collection: -TargetUrl "/sites/otherproject/Shared Documents". Looking at your code, it actually seems to be the SourceUrl that is the culprit. You are just pointing to the root of the users MySite. You need to select the appropriate document libraries and either iterate over files where you move, or maybe use RootFolder. This is also why you get 404: PowerShell does not know where to look for documents :) Also it is super confusing that you use both SPO and PnP. If you need to connect to multiple sites at once, just dedicate the connection using -ReturnConnection parameter and then use -Connection parameter when calling cmdlets $siteA = Connect-PnPOnline -ReturnConnection -Url "https://contoso.sharepoint.com/sites/siteA" Get-PnPListItem -List "Documents" -Connection $siteA |
Beta Was this translation helpful? Give feedback.
-
Thank you very much for the code examples! I implemented as follows:
I am able to connect to $siteA and $siteB without error.
I got:
As expected.
Returns:
I have tried several other URL combinations to connect to the testuser folder within PriorUsersOneDrive. All of them give errors when trying to connect. The full URL in $DestinationFolder above allows me to connect just fine. However, I cannot list items once connected (there is a test doc and a sample doc within $Destination Folder). Instead, I receive the above error. Interestingly, the following:
Returns:
As expected (including the testuser folder). This leads me to believe my connection to $SourceAccount.PersonalUrl is good, but I am having trouble with $DestinationFolder? Any suggestions as to why? And any suggestions as to how I accomplish the intended move of all contents from siteA to the specified folder in siteB? Again, thank you for looking at my issue so closely! |
Beta Was this translation helpful? Give feedback.
-
I believe I have determined that what I am trying to do (move files and folders directly from a user's OneDrive to a company SharePoint site) cannot work using Move-PnPFile. TLDR - Move-PnPFile cannot support two separate connections at the same time. For this use case, two separate connections are required. One Connection for the user's OneDrive and one connection for the target SharePoint site. Therefore, a straight transfer between a user's OneDrive for Business and a company SharePoint site using Move-PnPFile is not possible. I am upgrading this thread to an Issue to see if I can get verification or a better workaround. The OneDrive for Business folder exists at https://$ClientOrg-my.sharepoint.com/personal/testuser_clientdomain_com/Documents Those two domains appear to require two separate connections. So the following, using two separate connections, one for each command, works:
However, Move-PnpFile has and uses only one connection parameter. Therefore, depending on which connection you are using, you will get 'access denied' or '404 not found', etc. based on the connection used. I believe this is because they are different domains:
But this does:
I would very much love to have someone confirm my suspicion is correct, confirm the proposed workaround is correct, or tell me an elegant way to solve this puzzle. @veronicageek or anyone? |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello. Thank you for your hard work on this project. (especially @veronicageek - love the youtube channel). I am encountering the following errors when attempting to move the contents of a departed users OneDrive to a site library called 'PriorUsersOneDrive'. Each folder in PriorUsersOneDrive is named for the MailNickname of the user. Example: /sites/PriorUsersOneDrive/testuser if the email is testuser@mydomain.com.
I am able to connect just fine. I can Find-PnPFile in both sites just fine. I can Add-PnPFile to both sites just fine. I am a Global Admin and Site Collection Admin for both sites and have added code to (I hope) reinforce that ($GlobalAdminEmail entered previously and MFA authenticating just fine). I am using PnP.Powershell (1.8.0). Here is my code. I am pretty confident I don't need all the connect statements, but was trying to make 100% sure I was hitting the right spot, and removing that bit doesn't help.
I have also included my resulting output and thank you in advance for any assistance on why I am receiving this access denied error. I am 100% certain it is user error on my part and appreciate any insights in advance :):
Error text:
Again, finding and adding is working just fine:
Both of the above were run against the user's current OneDrive successfully
Beta Was this translation helpful? Give feedback.
All reactions