Hi.
I’m trying to accomplish a task regarding file copy from one Sharepoint document library within a site in one tenant (Sharepoint On-premisses) to a document library within another sharepoint site in another tenant (Sharepoint Online).
I have been digging around and wanted of course to take the cleanest path and most effective way (preserving meta data etc.), but are facing reality and my own lack of Sharepoint knowledge.
So I found a more primitive way where the files are just copied from the src to the destination.
To accomplish this, I want to create a New-PSDrive for each sites document library and simply copy each folder.
The below used to work for some time (though I got stuck in the copy process as the destination site refused, but I could at least map both drives and list their content, but not copy files).
Maybe this problem is related to the user running the process/script does not have access to either site?
Ok, the copy problem is one thing, but the problem right now is, that I’m not even able to map the destination drive/library.
I get the following error in my catch-block when running the script “The operation being requested was not performed because the user has not been authenticated.”.
The error message is in Danish, and I have translated it directly.
My research found that this could be related to the user setup to use MFA.
So I messed arond with both site permissions and Azure roles and created an app password to use in my credential file instead of the users regular password.
But I still get the same error.
Why did it suddenly stopped working with the mapping (no technical changes before it broke)?
And is there a way to attach permissions/credentials for the user running the mapping process to allow writing to the destination drive?
I hope somebody here can help point me in the right direction. Thanks!
SCRIPT BELOW (scraped for personal info)
**********************************************************
# Import credentials to use with sharepoint sites
$Credentials_XX = Import-CliXml -Path 'C:\OUTPUT\Creds_SP_XX.xml'
$Credentials_YY = Import-CliXml -Path 'C:\OUTPUT\Creds_SP_YY.xml'
try{
# Create the mapping for the *********** Sharepoint site
New-PSDrive -Name N -PSProvider "FileSystem" -Root "\\[Site_URL]" -Scope Global -Credential $Credentials_XX -ErrorAction Stop | Out-Null
Write-Host "N drive for *********** Sharepoint folder created succesfully..." -ForegroundColor Green
# Create the mapping for the *********** Sharepoint site
New-PSDrive -Name U -PSProvider "FileSystem" -Root "\\[Site_URL]" -Scope Global -Credential $Credentials_YY -ErrorAction Stop | Out-Null
Write-Host "U drive for *********** Sharepoint folder created succesfully..." -ForegroundColor Green
# Folder copy jobs
# Copy ZZZZZZZZ to *********** Sharepoint
$FolderToCopy = "N:\ZZZZZZZZ"
if(Test-Path -Path $FolderToCopy){
# Copy folder from N: to U:
Copy-Item -Path $FolderToCopy -Destination U: -Recurse
Write-Host "Folder 'ZZZZZZZZ' was succesfully copied to *********** Sharepoint." -ForegroundColor Green
}
}
catch{
Write-Host $_ -ForegroundColor Red
}
finally{
# Tear down the PS-drives after copy
if(Get-PSDrive -Name N -ErrorAction SilentlyContinue){
Remove-PSDrive -Name N -Force
Write-Host "PSDrive N was succesfully removed" -ForegroundColor Green
}
if(Get-PSDrive -Name U -ErrorAction SilentlyContinue){
Remove-PSDrive -Name U -Force
Write-Host "PSDrive U was succesfully removed" -ForegroundColor Green
}
}