2016-03-05 75 views
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

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

+1

'-Value' - >'-Name' – PetSerAl

+0

我想这就是它...谢谢 – Alex

回答

2

我会添加@PetSerAl的答案,所以我们可以关闭这个问题。

您使用了错误的文件名参数。与-Name更换-Value,例如:

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