title: Execute PowerShell remotely from TeamCity build using current agent credentials
body: <p>TeamCity executes builds using the build agents. The build agent I have is an agent on Windows that is running as a service under domain credentials.</p>
  
  <p>I need to Invoke-Command on a remote web server in one of my build steps.</p>
  
  <p>When I do this (lot's of stuff removed for simplicities sake):</p>
  
  <pre><code>$password = ConvertTo-SecureString "actualpasswordhere" -AsPlainText -Force
  $credentials = New-Object System.Management.Automation.PsCredential("domain\teamcityagent1",$password)
  ...
  Invoke-Command -computername $IISComputerName -Credential $credentials -ScriptBlock ${function:BackupSite} -ArgumentList $IISSiteName, $IISBackupDirectory
  </code></pre>
  
  <p>It works. But when I provide credentials for currently executing user like this:</p>
  
  <pre><code>$credentials = [System.Net.NetworkCredential]::DefaultCredentials
  </code></pre>
  
  <p>(surrounding code is the same)
  I get the internal waiting and not execution at the point of Invoke-Command. I haven't waited too long, but nothing happens even in 5 minutes.</p>
  
  <p>I would like not to have to provide login and password explicitly in the script, since the credentials are basically for the same user that the build agent is running under. How can I work around the need to provide the login and password in script code? </p>