开发者

Exchange PowerShell Script: "Assignment statements are not allowed in restricted language mode or a Data section"

I trying to execute the powershell script in C#. But I am getting the exception like "Assignment statements are not allowed in restricted language mode or a Data section."

Here is my C# code :

 string script = System.IO.File.ReadAllText(@"C:\script.ps1");

 PowerShell ex开发者_高级运维ec_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);
          }                       
}

Here is my PowerShell script :

[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)
}

wondering what is the problem.

Thanks is advance,

Viswanath B


It looks like it's a server restriction on Exchange: check this thread on technet.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜