2016-03-05 97 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