title: Access denied error while running PowerShell script
body: <p>I have written a script and i have put a condition that if server is pining search for below file and read the file content. but its giving error like below</p>
  
  <pre><code>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"
  </code></pre>
  
  <p>Error:</p>
  
  <pre>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</pre>
  
  <p>Can anyone correct me here to fix the issue?</p>