title: Get current user's credentials object in Powershell without prompting
body: <p>I have a Powershell script that is going to be run through an automation tool against multiple servers.</p>
  <p>It works fine on Windows machines, as the remote calls use the tool's service account without any need for prompting or exposing any credentials in code.</p>
  <p>This script also runs against Linux machines via SSH using the SharpSSH package. SharpSSH does not automatically use the Powershell user's credentials but requires either a username and password, an RSA key file, or a <code>PSCredential</code> object.</p>
  <p>I can't prompt for credentials using <code>Get-Credential</code>, because it's being run through the automation tool. I don't want to expose the username and password in code or have an RSA key sitting out there. I would like to construct a <code>PSCredential</code> object from the current Powershell user (the service account).</p>
  <p>Trying <code>[System.Net.CredentialCache]::DefaultNetworkCredentials</code> shows a blank, and <code>[System.Security.Principal.WindowsIdentity]::GetCurrent()</code> doesn't provide the object or information I need.</p>
  <p>Does anyone have a method for creating a <code>PSCredential</code> object from the current user? Or maybe a completely different alternative for this problem?</p>
  <p>Many thanks!</p>