-1
我已经写了一个脚本,并且我已经提出了一个条件,如果服务器正在寻找下面的文件并阅读文件内容。但它给错误像下面运行PowerShell脚本时访问被拒绝错误
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 : Access is denied At C:\Windows\TEMP\hudson4530962683016292267.ps1:65 char:5 + if (Test-Path $file) + ~~~~~~~~~~~~~~~ + CategoryInfo : PermissionDenied: (\\server1.us.o...\Image.log:String) [Test-Path], UnauthorizedAccessException + FullyQualifiedErrorId : ItemExistsUnauthorizedAccessError,Microsoft.PowerShell.Commands.TestPathCommand
任何人都可以纠正我这里来解决这个问题?
用于执行脚本的帐户无权读取'\\ server1.us.o ... \ Image.log'处的文件。 –
但我有权访问用户帐户的域管理员访问权限 – SNair
看起来您正在Jenkins中运行此操作。使用哪个帐户?在你的脚本中添加一个“whoami”以确认。您可能需要为该用户而不是c $创建只读共享。 –