title: Powershell data read from file contains dollar sign $
body: <p>I have a powershell script that is reading a password from a file, the password has been 'secured' using a generated AES Key.  There are three files used in the process</p>
  
  <p>AES Key File Generation:</p>
  
  <pre><code>$KeyFile = "\\server\path\AES.key"
  $Key = New-Object Byte[] 16
  [Security.Cryptography.RNGCryptoServiceProvider]::Create().GetBytes($Key)
  $Key | out-file $KeyFile
  </code></pre>
  
  <p>Password File Generation:</p>
  
  <pre><code>$PasswordFile = "\\server\path\Password.txt"
  $KeyFile = "\\server\path\AES.key"
  $Key = Get-Content $KeyFile
  $Password = "Sy$tem@dmin" | ConvertTo-SecureString -AsPlainText -Force
  $Password | ConvertFrom-SecureString -key $Key | Out-File $PasswordFile
  </code></pre>
  
  <p>Script That Grabs Password File and Converts back to Plain Text:</p>
  
  <pre><code>$User = "myuser"
  $PasswordFile = "\\server\path\Password.txt"
  $KeyFile = "\\server\path\AES.key"
  $key = Get-Content $KeyFile
  $MyCredential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $User, (Get-Content $PasswordFile | ConvertTo-SecureString -Key $key)
  $PlainPassword2 = $MyCredential.GetNetworkCredential().Password
  $PlainPassword2
  </code></pre>
  
  <p>The conversion back to plain text is really being done just so we can verify that the data is the same as what was initially created.</p>
  
  <p>When we display the data contained in $PlainPassword2 instead of seeing <strong>Sy$tem@dmin</strong> as is expected, we are seeing <strong>Sy@dmin</strong>.</p>
  
  <p>What can we do to correct this?</p>