I have a ps script that moves all images from a staging folder to a set of sub-folders that are created for the pictures in yyyy\yyyy-MM\ naming pattern. This script runs fine in folders that are not in the local OneDrive folder, but fails for any file that is in OneDrive. I've narrowed it down to not being able to create folders or to move files using PowerShell (or Window Command Prompt) when the file is in OneDrive.
Powershell (and command prompt) is able to list the files in the folders, but not create or move them.
If I do it manually in Windows Explorer, there are no errors, I can create folders, move, delete, etc.
This is in Windows 11 23H2, with PSVersion 5.1.22621.2506, logged in to windows with the same microsoft account used for the OneDrive, for a personal account (not business OneDrive)
Examples
In OneDrive, fails:
PS C:\users\xxxx\OneDrive\Documents> new-item 'testDir' -Type Directory
new-item : Could not find file 'testDir'.
At line:1 char:1
+ new-item 'testDir' -Type Directory
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : WriteError: (C:\users\xxxx\...cuments\testDir:String) [New-Item], FileNotFoundException
+ FullyQualifiedErrorId : CreateDirectoryIOError,Microsoft.PowerShell.Commands.NewItemCommand
Not in OneDrive, succeeds:
PS C:\users\xxxx\Documents> new-item 'testDir' -Type Directory
Directory: C:\users\xxxx\Documents
Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 2/6/2024 5:35 PM testDir
***moved from Windows / Windows 11 / Files, folders, and storage***