Hi 10101 0x3F,
Try pausing OneDrive sync temporarily while running the PowerShell script. Also specify the full path with the -Path parameter and see if the issue persists.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
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***
Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question. To protect privacy, user profiles for migrated questions are anonymized.
Hi 10101 0x3F,
Try pausing OneDrive sync temporarily while running the PowerShell script. Also specify the full path with the -Path parameter and see if the issue persists.
I still have the same issue. I stopped the OneDrive sync using the notification area, and when that didn't work I killed all processes and services named OneDrive or OneSync...
The powershell command I tried and the error message:
PS C:\users\xxxx\OneDrive\Documents> new-item -path . -name "testdir" -type Directory
new-item : Could not find file 'testdir'.
At line:1 char:1
+ new-item -path . -name "testdir" -type Directory
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : WriteError: (C:\users\xxxx\...cuments\testdir:String) [New-Item], FileNotFoundException
+ FullyQualifiedErrorId : CreateDirectoryIOError,Microsoft.PowerShell.Commands.NewItemCommand
What if the full path is specified with the -Path parameter?
new-item -path "C:\users\xxxx\OneDrive\Documents\testdir" -type Directory
# Define the path to the OneDrive Documents folder
$OneDrivePath = [Environment]::GetFolderPath('MyDocuments')
# Define the name of the new folder
$NewFolderName = "Citavi 6"
# Combine the paths
$NewFolderPath = Join-Path -Path $OneDrivePath -ChildPath $NewFolderName
# Create the new folder
New-Item -ItemType Directory -Path $NewFolderPath -Force
Write-Output "New folder created at: $NewFolderPath"
I have exact the same Problem. The folder not exist