我对 powershell 还不熟悉,所以也许这是一个简单的解决方法。我以管理员身份运行 powershell,所以我应该能够做我想做的事——但是我无论如何也想不出这个问题。创建新文件会引发错误,这毫无道理'FileNotFound'
……我正在尝试创建一个该死的文件,当然它还没有完成!
我正在使用 powershell 5.1.18362.1171
PS C:\Users\<myname>\OneDrive - <othername>\Documents\transport\d3 stuff> New-Item -name testfile1.txt -ItemType file -force
New-Item : Could not find file 'C:\Users\<myname>\OneDrive - <othername>\Documents\transport\d3 stuff\testfile1.txt'.
At line:1 char:1
+ New-Item -name testfile1.txt -ItemType file -force
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : WriteError: (C:\Users\M31252...f\testfile1.txt:String) [New-Item], FileNotFoundException
+ FullyQualifiedErrorId : NewItemIOError,Microsoft.PowerShell.Commands.NewItemCommand
但是我可以在其他目录中创建文件,也许这与路径扩展有关,因为我试图在带有空格的路径中创建文件?
PS C:\Users\m31252> New-Item -Path . -Name "testfile1.txt" -ItemType "file" -Value "text string"
Directory: C:\Users\m31252
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 4/8/2021 2:25 PM 11 testfile1.txt
答案1
该问题似乎是权限错误:
PS C:\Users\<myname>> (get-acl '.\OneDrive - <othername>\learning d3\').Access
FileSystemRights : DeleteSubdirectoriesAndFiles
AccessControlType : Deny
IdentityReference : Everyone
IsInherited : True
InheritanceFlags : ContainerInherit
PropagationFlags : None
FileSystemRights : FullControl
AccessControlType : Allow
IdentityReference : NT AUTHORITY\SYSTEM
IsInherited : True
InheritanceFlags : ContainerInherit, ObjectInherit
PropagationFlags : None
FileSystemRights : FullControl
AccessControlType : Allow
IdentityReference : BUILTIN\Administrators
IsInherited : True
InheritanceFlags : ContainerInherit, ObjectInherit
PropagationFlags : None
FileSystemRights : FullControl
AccessControlType : Allow
IdentityReference : <thirdname>
IsInherited : True
InheritanceFlags : ContainerInherit, ObjectInherit
PropagationFlags : None
PS C:\Users\<myname>> (get-acl '.\OneDrive - <othername>\Documents\').Access
FileSystemRights : FullControl
AccessControlType : Allow
IdentityReference : NT AUTHORITY\SYSTEM
IsInherited : False
InheritanceFlags : ContainerInherit, ObjectInherit
PropagationFlags : None
FileSystemRights : FullControl
AccessControlType : Allow
IdentityReference : <thirdname>
IsInherited : False
InheritanceFlags : ContainerInherit, ObjectInherit
PropagationFlags : None
当尝试更改问题目录的 ACL 时,我得到了一个UnauthorizedAccessException
支持这个想法的消息。现在要弄清楚如何获得更改此 ACL 的权限...