We had a customer what moved all file share data to a teams channel. after migration, not all files could be open om Teams. File extention is different, not attached to one specific app. Opening the files via Sharepoint was no issue. First issue what I tough was Onedrive or Teams reset. Did it, but was not solving. When I did that, I heared others have the same issue.
Next thing I tough about File length. but after checking, it was less than 400 characters.
Restrictions and limitations in OneDrive and SharePoint – Microsoft Support
After some test, we found out that when download a file, delete the online file and place the file back with the same name, the file could be opened without issues. Looks like the Meta data of the file is corrupted.
Ok. Now I have a solution, but how to do this with 50 GB of data and over 40.000 files to check.
Then found 2 ways, Connect the Sharepoint to a Onedrive. and do the local copy job. “Download” the files, Move it outside Sharepoint or on a new Sharepoint folder. But when you are doing this, there are some negative points.
- Downloading and Uploading costs a lot of time
- Owner name / last modified name is changed.
- Version history is lost.
- Data is temporary not available.
Based on the points above it was not the good way.
The other way maybe better. A Powershell script that connects to Sharepoint online, and do a move internally in Sharepoint online. This is the best way to skip all the negative points above.
Now its clear what to do, because I’m admin of the tenant but I don’t have a system in that tenant, and I don’t want to use my own system, I created a Hyper-V VM on my own system.
Installed the Default Windows 11 Image from Microsoft on the VM.
Now I’m trying to sign in with a test account on that system. Mm, that’s not working. Found out that system is blocked by Intune policy (Enrollment restriction) that don’t allow Personally owned devices to add the the tenant.

Example above.
I created a new Enrollment restriction what is automatically placed above the default restriction. And add only personally owned to allow.
Added a new AAD group and add the test account in it. Added the AAD group to the new Enrollment restriction policy. Now waited 5 minutes and tried again. Finally signed in is working.
Next step. Install PnP.PowerShell module.
Start Powershell as Admin on the system. and type the following command to install the module.
Install-Module PnP.PowerShell -Scope CurrentUser -Force
When you get the message about NuGet update. Press Y and enter.

Type
Get-Module PnP.PowerShell -ListAvailable
You should get info about what module is installed.
On the default Windows 11 25h2 Powershell 5.1 is installed and wont give any output about the module that is installed.

Issue here is the PnP.Powershell module is working on minimal PowerShell 7.4.0.
So first we need to update Powershell to the latest. Easy way to update is trough Winget.
Type in the current powershell window the following command to install the latest Powershell version
winget install --ID Microsoft.PowerShell --Source winget
Now is PowerShell Automatic installed.

Close current Powershell (5.1)
Open the new Powershell 7 (x64) as Admin.

Run the command
Install-Module PnP.PowerShell -Scope CurrentUser -Force
And then to check if its installed.
Get-Module PnP.PowerShell -ListAvailable
Result:

Now you need to connect to the Sharepoint tenant. Because all the security at Microsoft is higher than it was before. You cannot start connecting with username and password. Now you need to Register an Application with the correct rights to continue
With the website Connect to SharePoint Online using PnP PowerShell – SharePoint Diary I found the solution.
The following code you need to enter in the Powershell 7 and edit the Tenantname:
Register-PnPEntraIDAppForInteractiveLogin -ApplicationName "PnP PowerShell" -SharePointDelegatePermissions "AllSites.FullControl" -Tenant Tenantname.onmicrosoft.com
Edge browser will automatic be opened Fill in the Admin username and password, and MFA. Then you get the message to close the browser.

Powershell is still running, and after 30 seconds the browser opens again. You need to Sign in again. After that you need to accept the following window.

Now the App is registered with the correct rights.
In the Powershell output, Save the ClientID for connecting to

You can check if the connection is working with
Get-PnPWeb
Now we can connect to the Sharepoint with Powershell with the following code (Change <TENANTNAME> And <SITENAME>, and the CLIENTID.
$SiteURL = "https://<TENNANTNAME>.sharepoint.com/sites/<SITENAME>"
Connect-PnPOnline -Url $SiteURL -Interactive -ClientId "<CLIENTID>"
Now you can test a file if this fix the issue, You need to validate the locations because of language. Add/Change location of the test file. (Code is generated by ChatGPT)
$library = "Documenten"
$channel = "Algemeen"
$tempFolder = "TempRehydrate"
$dryRun = $True
$testFile = "Gedeelde documenten/General/<LOCATION OF A TEST FILE>"
Write-Host "== Test 1 bestand ==" -ForegroundColor Cyan
Write-Host "Bestand:" $testFile
Write-Host "Dry-run:" $dryRun
# Temp folder maken (alleen echte run)
if (-not $dryRun) {
Add-PnPFolder -Name $tempFolder -Folder "$library/$channel" -ErrorAction SilentlyContinue
}
# Naar temp
$targetUrl = $testFile -replace "$library/$channel", "$library/$channel/$tempFolder"
Write-Host "→ Naar temp:" $targetUrl
if (-not $dryRun) {
Move-PnPFile -SourceUrl $testFile -TargetUrl $targetUrl -Force
}
# Terug
$originalUrl = $targetUrl -replace "$library/$channel/$tempFolder", "$library/$channel"
Write-Host "← Terug:" $originalUrlif
(-not $dryRun) {
Move-PnPFile -SourceUrl $targetUrl -TargetUrl $originalUrl -Force
}
Write-Host "== Test klaar ==" -ForegroundColor Green
If the Test is working, Change $dryRun = $False
Now it moves the file.
When I did this, somehow it updated the whole Sharepoint site, and all files was accessable trough Teams.
I did some commands with
Get-PnPListItem -List "Documenten"
Because I could not get the correct directory. You can use this to browse in the sharepoint.
Add after Documenten/<Foldername> to go in to a folder.
When done, don’t forget to remove if you are done and not needed anymore.
- Enterprise Application (Link)
- App registration (Link) (check All Applications)
- Remove the created AAD group
- Remove the temp Enrollment restrictions (Link) if created
- Remove the Device (Link)