【问题标题】:Exchange PowerShell Script: "Assignment statements are not allowed in restricted language mode or a Data section"Exchange PowerShell 脚本:“在受限语言模式或数据部分中不允许赋值语句”
【发布时间】:2011-03-16 07:56:40
【问题描述】:

我试图在 C# 中执行 powershell 脚本。但我得到了“在受限语言模式或数据部分中不允许赋值语句”之类的异常。

这是我的 C# 代码:

字符串脚本 = System.IO.File.ReadAllText(@"C:\script.ps1"); PowerShell exec_script = PowerShell.Create(); exec_script.RunspacePool = rs; exec_script.AddScript(脚本); IAsyncResult exec_AsyncResult = exec_script.BeginInvoke(); PSDataCollection exec_Result = exec_script.EndInvoke(exec_AsyncResult); foreach(exec_Result 中的 PSObject cmdlet) { PSMemberInfoCollection 集合 = cmdlet.Members; foreach(集合中的 PSMemberInfo 临时) { Console.WriteLine(temp.Name + "\t\t\t\t:\t" + temp.Value); } }

这是我的 PowerShell 脚本:

[Collections.ArrayList]$serverList = New-Object Collections.ArrayList
[字符串]$服务器

if ($server -eq "")
{
                $objects = 获取邮箱服务器
                foreach ($objects 中的$object)
                {
                                $out = $serverList.Add($object.Name)
                }
}

别的
{
                $serverList.Add($server)
}

想知道是什么问题。

先谢谢了,

维斯瓦纳特 B

【问题讨论】:

    标签: c# powershell


    【解决方案1】:

    这似乎是 Exchange 的服务器限制:检查 this thread on technet

    【讨论】:

      猜你喜欢
      • 2014-03-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-06
      • 2015-08-28
      • 1970-01-01
      • 1970-01-01
      • 2020-04-24
      相关资源
      最近更新 更多