title: Powershell: Cannot convert 'System.String' to the type 'System.Management.Automation.SwitchParameter' required by parameter 'AsPlainText'
body: <p>Iam running following script in powershell. (its saved in temp.ps1 file)</p>
  
  <pre><code>[String]$ServiceAccountPassword ='Password'
  $secpass = ConvertTo-SecureString –String $ServiceAccountPassword –AsPlainText -Force 
  </code></pre>
  
  <p>When I run it from powershell ISE it works fine.</p>
  
  <p>But when call this script from c# application i.e. </p>
  
  <pre><code>_powerShell = PowerShell.Create();
  var sr = new StreamReader(scriptFile);
  _powerShell.AddScript(sr.ReadToEnd());
  _powerShell.InvocationStateChanged += _powerShell_InvocationStateChanged;
  var outputCollection = new PSDataCollection&lt;PSObject&gt;();
  outputCollection.DataAdded += outputCollection_DataAdded;
  _powerShell.Streams.Error.DataAdded += Error_DataAdded;
  IAsyncResult async =_powerShell.BeginInvoke&lt;PSObject, PSObject&gt;(null,     outputCollection, null, AsyncInvoke, null);
  </code></pre>
  
  <p>I am getting</p>
  
  <p><strong><em>Cannot convert 'System.String' to the type     'System.Management.Automation.SwitchParameter' required by parameter     'AsPlainText'.</em></strong> </p>