title: using credentials to Test-Path isn't working
body: <p>I'm writing a script to check that our backup succeeded.  Unfortunately, the backup is in a different location/login.  The script is scheduled to run without user intervention, like the other ones do.  I'm adding in credential info that is saved, but the -Credential option isn't working.  It's still asking me to enter the login info in a popup login window, even with the -credential option I'm using.  Do you see an issue with the following?  I know the secure login works with another script so I don't think there's a problem with it's creation.  I think the problem is in using the credentials with Test-Path. From what I can see, I think I'm doing it correctly, according to this link, although they aren't using a stored credential like I am: <a href="http://social.technet.microsoft.com/Forums/windowsserver/en-US/58a86256-f9be-4042-93a6-e8339132e20b/testpaths-credential-parameter-is-it-ever-used?forum=winserverpowershell" rel="nofollow">test-path with cred</a></p>
  
  <pre><code>function GetSecureLogin (){
  #this function will obtain secure login
     $TISusername = "username/here"
     #read-host -assecurestring | convertfrom-securestring | out-file C:\filename.txt
     #Note: when you save password for re-use as above, programs that use it later must be using same login as had when saved password: ie. Script_Guru
     $TISpassword = get-content  C:\Scripts\filename.txt | convertto-securestring #may not need to re-convert to secure string since stored secure string
     $global:cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $TISusername, $TISpassword
  
  }
  
  Function CheckBackedUp($file, $destinationFolder)
  {
  
      #get filename without folder
      $filename = $file.substring($file.lastindexofany("\") +1 ,$file.length - ($file.lastindexofany("\")+1)) 
  
      #$destinationFolder = split-path($file)
      #get date and append to fileNameWithoutExt
      #$ext = Get-Date -uformat "%Y-%m-%d" 
      $ext = "2014-06-11"
      $newFileName = $destinationFolder+"\"+$ext+"*"+$filename
      #look for file
      if(Test-Path "$newFileName" -Credential $global:cred) #this isn't working
      {
         Write-Host "$newFileName exists"
      }
      else
      {
          $temp = "$newFileName doesn't exist. "
          Write-Host "$temp "
          $global:resultMessage += $temp
  
      }
  
      #return failure message if don't find file with signature that contains $ext
  
  } #CheckBackedUp
  
  ####start here
  ...
  $global:cred = ""
  GetSecureLogin
  
  $global:resultMessage = ""
  
  #loop through files, checking if we backed each one up
  $i=0
  try{
  for ($i = $fileArray.GetLowerBound(0); $i -le $fileArray.GetUpperBound(0); $i++) { 
          $tempSource =  $fileArray[$i]
          #see if files were correctly backed up
          CheckBackedUp $tempSource $TisToLocation
  }
  ...
  </code></pre>
  
  <p><strong>**Update 6/27/2014**</strong>
  When I tried using the following in place of the Test-Path if statement above</p>
  
  <pre><code>invoke-command -computername "usa02xxnas1.na.xxx.net" -credential $globalcred -scriptblock{Test-Path "$newFileName"}
  </code></pre>
  
  <p>I got this error message, which I don't understand how to fix:</p>
  
  <pre><code>[usa02xxxnas1.na.xxx.net] Connecting to remote server usa02xxnas1.na.xxx.net failed with the following error message : WinRM cannot process the request. The following error 
  with errorcode 0x80090311 occurred while using Kerberos authentication: There are currently no logon servers available to service the logon request.  
   Possible causes are:
    -The user name or password specified are invalid.
    -Kerberos is used when no authentication method and no user name are specified.
    -Kerberos accepts domain user names, but not local user names.
    -The Service Principal Name (SPN) for the remote computer name and port does not exist.
    -The client and remote computers are in different domains and there is no trust between the two domains.
   After checking for the above issues, try the following:
    -Check the Event Viewer for events related to authentication.
    -Change the authentication method; add the destination computer to the WinRM TrustedHosts configuration setting or use HTTPS transport.
   Note that computers in the TrustedHosts list might not be authenticated.
     -For more information about WinRM configuration, run the following command: winrm help config. For more information, see the about_Remote_Troubleshooting Help topic.
      + CategoryInfo          : OpenError: (usa02xxnas1.na.xxx.net:String) [], PSRemotingTransportException
      + FullyQualifiedErrorId : AuthenticationFailed,PSSessionStateBroken
  </code></pre>