如何授予创建新文件的权限?
How to grant access to create a new file?
我尝试使用 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 上的 Administrator PowerShell 2.0 window 中执行脚本。该目录存在,但如何修复此错误?
我将添加@PetSerAl 的回答,这样我们就可以结束这个问题了。
您使用了错误的文件名参数。将 -Value
替换为 -Name
,例如:
New-Item -Path $LogDir -Name $LogName -Force -ItemType File
我尝试使用 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 上的 Administrator PowerShell 2.0 window 中执行脚本。该目录存在,但如何修复此错误?
我将添加@PetSerAl 的回答,这样我们就可以结束这个问题了。
您使用了错误的文件名参数。将 -Value
替换为 -Name
,例如:
New-Item -Path $LogDir -Name $LogName -Force -ItemType File