title: Exchange PowerShell Script: "Assignment statements are not allowed in restricted language mode or a Data section"
body: <p>I trying to execute the powershell script in C#. But I am getting the exception like <strong>"Assignment statements are not allowed in restricted language mode or a Data section."</strong></p>
  
  <p><strong>Here is my C# code :</strong></p>
  
  <pre>
   string script = System.IO.File.ReadAllText(@"C:\script.ps1");
  
   PowerShell exec_script = PowerShell.Create();
   exec_script.RunspacePool = rs;
   exec_script.AddScript(script);
  
  IAsyncResult exec_AsyncResult = exec_script.BeginInvoke();
  PSDataCollection exec_Result = exec_script.EndInvoke(exec_AsyncResult);
  
  foreach (PSObject cmdlet in exec_Result)
  {   
            PSMemberInfoCollection collec = cmdlet.Members;                       
            foreach (PSMemberInfo temp in collec)
            { 
                      Console.WriteLine(temp.Name + "\t\t\t\t:\t" + temp.Value);
            }                       
  }
  </pre>
  
  <p><strong>Here is my PowerShell script :</strong></p>
  
  <pre>[Collections.ArrayList]$serverList = New-Object Collections.ArrayList
  [string]$server
  
  if ($server -eq "")
  {
                  $objects = Get-MailboxServer
                  foreach ($object in $objects)
                  {
                                  $out = $serverList.Add($object.Name)
                  }
  }
  
  else
  {
                  $serverList.Add($server)
  }
  </pre>
  
  <p>wondering what is the problem.</p>
  
  <p>Thanks is advance,</p>
  
  <p><strong>Viswanath B</strong></p>