首页 文章

如何授予访问权限以创建新文件?

提问于
浏览
0

使用PowerShell脚本,我尝试创建一个新文件,如下所示:

New-Item -Path $LogDir -Value $LogName -Force -ItemType File

哪个被以下错误消息拒绝:

New-Item : Access to the path 'D:\Testing\Data\Powershell\Log' is denied.
At D:\Testing\Data\Powershell\LoadRunner\LRmain.ps1:27 char:9
+ New-Item <<<<  -Path $LogDir -Value $LogName -Force -ItemType File
    + CategoryInfo          : PermissionDenied: (D:\Testing\Data\Powershell\Log:String) [New-Item], UnauthorizedAccessException
    + FullyQualifiedErrorId : NewItemUnauthorizedAccessError,Microsoft.PowerShell.Commands.NewItemCommand

我正在Windows Server 2008上的管理员PowerShell 2.0窗口中执行该脚本 . 该目录存在,但我该如何解决此错误?

1 回答

  • 2

    我将添加@ PetSerAl的答案,以便我们可以关闭这个问题 .

    您使用了错误的文件名参数 . 将 -Value 替换为 -Name ,例如:

    New-Item -Path $LogDir -Name $LogName -Force -ItemType File
    

相关问题