I can't create a folder (eg called test) in my user's Desktop folder:
cd c:\Users\praful\Desktop
mkdir test
The same happens in Favorites, which is also a special (known) folder.
The same happens with administrator account.
I can't delete a file using:
PS> cd c:\users\praful\desktop
rm test.txt
In PowerShell 5.1, a folder is created called test.
In PowerShell 5.1, a file called test.txt can be deleted.
The following error occurs when trying to create a folder called test:
mkdir : Could not find file 'C:\users\praful\Desktop\test'.
At line:1 char:1
+ mkdir test
+ ~~~~~~~~~~
+ CategoryInfo : WriteError: (C:\users\praful\Desktop\test:String) [New-Item], FileNotFoundException
+ FullyQualifiedErrorId : CreateDirectoryIOError,Microsoft.PowerShell.Commands.NewItemCommand
More details:
PS> $error[0] |fl * -f
writeErrorStream : True
PSMessageDetails :
Exception : System.IO.FileNotFoundException: Could not find file
'C:\users\praful\Desktop\test'.
File name: 'C:\users\praful\Desktop\test'
at System.IO.FileSystem.CreateDirectory(String fullPath)
at System.IO.Directory.CreateDirectory(String path)
at Microsoft.PowerShell.Commands.FileSystemProvider.Creat
eDirectory(String path, Boolean streamOutput)
TargetObject : C:\users\praful\Desktop\test
CategoryInfo : WriteError: (C:\users\praful\Desktop\test:String)
[New-Item], FileNotFoundException
FullyQualifiedErrorId : CreateDirectoryIOError,Microsoft.PowerShell.Commands.NewItem
Command
ErrorDetails :
InvocationInfo : System.Management.Automation.InvocationInfo
ScriptStackTrace : at <ScriptBlock><Process>, <No file>: line 52
at <ScriptBlock>, <No file>: line 1
PipelineIterationInfo : {0, 1}
The following error occurs when trying to delete a file test.txt in the Desktop folder:
The error is:
rm : Access to the path 'C:\users\praful\Desktop\test.txt' is denied.
At line:1 char:1
+ rm .\test.txt
+ ~~~~~~~~~~~~~
+ CategoryInfo : PermissionDenied: (C:\users\praful\Desktop\test.txt:FileInfo) [Remove-Item], UnauthorizedAccessException
+ FullyQualifiedErrorId : RemoveFileSystemItemUnAuthorizedAccess,Microsoft.PowerShell.Commands.RemoveItemCommand
This is not a permissions issue because the create folder and remove file commands work with the same user with PowerShell 5.1.
$PSVersionTable
Name Value
---- -----
PSVersion 6.1.2
PSEdition Core
GitCommitId 6.1.2
OS Microsoft Windows 10.0.17763
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
The same occurred in PS 6.2 preview 4, which is why I installed 6.1.2. Having just installed PS v6, I feel I must be doing (or not doing) something simple!
After looking further into this, it seems that PS 6 is not honouring folder ACLs. The issue is not limited to special folders. I've had it on other folders where I'm a member of a group.
To reproduce:
testgroup. To create group, use app Computer Management, System Tools, Local Users and Groups. test-folder).testgroup group has full access but no other group has access. test-folder folder and try to create a folder in it. It fails.test-folder so that Authenticated Users have Full Control.test-folder. It will succeed.I actually have this problem on Powershell 5.1, so it may not be isolated to Powershell 6.1.
PowerShell doesn't process ACLs. It calls .Net Core methods and system APIs.
You need look effective permissions and third-party applications like anti-virus.
In case others find it useful: my issue was caused by Windows 10 controlled folders. Usually a notification occurs when an application is blocked. For some reason, the blocked folder notifications have stopped. The solution is to whitelist pwsh.exe.
holy crap this is insane i couldn't do it with CMD either. Had to whitelist in Windows Defender Security Center as stated by Praful. Under options > Settings > Virus and threat Protection Settings > Managed controlled folder access > "Allow an papp through Controlled folder access"
Most helpful comment
In case others find it useful: my issue was caused by Windows 10 controlled folders. Usually a notification occurs when an application is blocked. For some reason, the blocked folder notifications have stopped. The solution is to whitelist pwsh.exe.