【发布时间】:2017-02-28 06:11:03
【问题描述】:
我已经编写了一个脚本,并且我设置了一个条件,即如果服务器正在搜索下面的文件并读取文件内容。但它给出的错误如下所示
if ((Test-Connection -ComputerName $fqdn -Count 1 -Quiet) -eq 1)
{
$Value = "Host is pinging"
$searchtext = "Imaging Completed"
$file = "\\$fqdn\C$\Image.log"
if (Test-Path $file)
{
if (Get-Content $file | Select-String $searchtext -quiet)
{
Write-Host "$fqdn Imaging Completed"
错误:
Test-Path : 访问被拒绝
在 C:\Windows\TEMP\hudson4530962683016292267.ps1:65 char:5
+ if (测试路径 $file)
+~~~~~~~~~~~~~~~
+ CategoryInfo : PermissionDenied: (\\server1.us.o...\Image.log:String) [Test-Path], UnauthorizedAccessException
+ FullyQualifiedErrorId : ItemExistsUnauthorizedAccessError,Microsoft.PowerShell.Commands.TestPathCommand
谁能在这里纠正我来解决这个问题?
【问题讨论】:
-
执行脚本的账号没有
\\server1.us.o...\Image.log文件的读取权限。 -
但我可以访问域管理员访问用户帐户
-
看起来你正在 Jenkins 中运行它。那是用什么账号?在你的脚本中添加一个“whoami”来确定。您可能需要为该用户创建一个只读共享而不是 c$。
-
它说 nt authority\system!!!我不确定这个帐户 t 是如何用于运行脚本的
-
将有效凭据添加到您的
Test-Connection
标签: powershell jenkins