title: Syntax not supported by this runspace in Powershell and C#
body: <p>I am trying to get information about my users' mailboxes using power shell integrated into C#, but i am getting below error: </p>
  
  <pre><code>This syntax is not supported by this run space. This might be because it is no-language mode.
  </code></pre>
  
  <p>Here is the code that I am using:</p>
  
  <pre><code>using System;
  using System.Collections.ObjectModel;
  using System.Collections;
  using System.Linq;
  using System.Text;
  using System.Management.Automation;
  using System.Management.Automation.Runspaces;
  using System.Threading;
  using System.Globalization;
  
  namespace Office365
  {
      class Program
      {
          static void Main(string[] args)
          {
              CultureInfo oldCI = Thread.CurrentThread.CurrentCulture;
              Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("en-US");
              Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US");
  
              System.Security.SecureString secureString = new System.Security.SecureString();
              string myPassword = "mySecretPassword";
              foreach (char c in myPassword)
                  secureString.AppendChar(c);
              PSCredential credential = new PSCredential("my@maildomain.com", secureString);
              Console.WriteLine("Forbinder....");
              WSManConnectionInfo connectionInfo = new WSManConnectionInfo(new Uri("https://ps.outlook.com/PowerShell-LiveID?PSVersion=2.0"), "http://schemas.microsoft.com/powershell/Microsoft.Exchange", credential);
              connectionInfo.AuthenticationMechanism = AuthenticationMechanism.Basic;
              connectionInfo.SkipCACheck = true;
              connectionInfo.SkipCNCheck = true;
  
              string cmd2 = @"Get-Mailbox | Select-object Identity, displayname, ProhibitSendReceiveQuota, @{n='size';e={$MBXSTAT=Get-MailboxStatistics $_.Identity; $MBXSTAT.TotalItemSize}}";
  
              using (Runspace runspace = RunspaceFactory.CreateRunspace(connectionInfo))
              {
  
                      runspace.Open();
  
                  using (Pipeline pipeline = runspace.CreatePipeline(cmd2))
                  {
                      pipeline.Commands.AddScript(cmd2);
                      Collection&lt;PSObject&gt; results = pipeline.Invoke();
                      foreach (PSObject obj in results)
                      {
  
                          // Do something with each result object
                      }
                  }
              }
          }
  }
  </code></pre>
  
  <p>Any Suggestions on this? How can I overcome to this issue?</p>