0
votes

With a PowerShell script I try to create a new file as follows:

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

which is refused with the following error messsage:

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

I am executing the script in an Administrator PowerShell 2.0 window on Windows Server 2008. The directory exists, but how can I fix this error?

1
I guess thats it ... thanks - Alex

1 Answers

2
votes

I'll add @PetSerAl's answer so we can close this question.

You've used the wrong parameter for the filename. Replace -Value with -Name, ex:

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