title: Method invocation failed because [System.String] does not contain a method named 'GetNetworkCredential'
body: <p>I have a PowerShell script that creates a XML file with the username and password for a SQL Server database.</p>
  
  <p>Script:</p>
  
  <pre><code>Get-Credential –Credential (Get-Credential) |
      Export-CliXml "$FileLocation\DatabaseCredentials-$SQLServer.xml"
  </code></pre>
  
  <p>This script works file, however when I try to read the username and password from the XML file I get the following error:</p>
  
  <pre>
  Method invocation failed because [System.String] does not contain a method
  named 'GetNetworkCredential'.
  At line:18 char:1
  + $DatabasePassword = $Credentials.GetNetworkCredential().Password
  + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
      + FullyQualifiedErrorId : MethodNotFound
  </pre>
  
  <p>Script:</p>
  
  <pre><code>$Credentials = Import-CliXml '$FileLocation\DatabaseCredentials-$SQLServer.xml'
  
  $DatabaseUserName = $Credentials.UserName
  $DatabasePassword = $Credentials.GetNetworkCredential().Password
  </code></pre>