title: How to read PowerShell .PSD1 files safely
body: <p>The PowerShell module manifest file format (.psd1) is essentially a Hashtable literal with certain keys expected. This is ideal for a configuration file for a PowerShell script. What I ultimately want to do is read a .psd1 file that contains a set of keys specific to the script.</p>
  
  <p>For example (MyScriptConfig.psd1):</p>
  
  <pre><code>@{
      FTPHost = "ftp.blah.com"
      FTPUserName = "blah"
      FTPPassword = "blah"
  }
  </code></pre>
  
  <p>There's no reason I can't use XML, INI, JSON or whatever for this information, but I'd rather it use the same basic data format as PowerShell's module manifests.</p>
  
  <p>Obviously the easiest thing would be to read the text and pass it to <code>Invoke-Expression</code> which would return a Hashtable, but then it would invoke anything that's in the file, which is error prone and potentially unsafe.</p>
  
  <p>I thought I recalled a cmdlet for reading this data using a "safe" subset of PowerShell cmdlets, but I was thinking of <code>ConvertFrom-StringData</code> and <code>DATA</code> sections, neither of which let me read an arbitrary file containing a Hashtable literal.</p>
  
  <p>Is there something built into PowerShell that lets me do this? If there's nothing built in, then I would probably go the route of JSON or Key=Value with <code>ConvertFrom-StringData</code>.</p>