我编写了一个代码,可以使用PowerShell启用MS Exchange ActiveSync设置。当它部署在测试环境中时,一切正常,但在PROD上它会抛出错误。
ASP.NET代码
employeeDropDownModel>/employmentNav/personNav/personalInfoNav/results/firstName
employeeDropDownModel>/employmentNav/personNav/personalInfoNav/results/0/firstName
PowerShell代码
$.each(
this.employeeModel,function(index, value) {
if (value.employmentNav.personNav.personalInfoNav.results.length > 0) {
var firstName = value.employmentNav.personNav.personalInfoNav.results[0].firstName;
var lastName = value.employmentNav.personNav.personalInfoNav.results[0].lastName;
value['firstName'] = firstName;
value['lastName'] = lastName;
} else {
value['firstName'] = '';
value['lastName'] = '';
}
});
我无法使用以下异常猜测任何问题。
错误明细如下
的类型初始值设定项
string scriptFile = HttpContext.Current.Server.MapPath("~/PSScripts/ActiveSync.ps1");
//Create runspace
var runspace = RunspaceFactory.CreateRunspace();
runspace.Open();
// create a pipeline and feed it the script text
var pipeline = runspace.CreatePipeline();
var scriptCommand = new Command(scriptFile);
//Add parameters
foreach (var p in Parameters)
scriptCommand.Parameters.Add(p);
//Read parameters from the database
scriptCommand.Parameters.Add(new CommandParameter("ActionType", ActionType));
pipeline.Commands.Add(scriptCommand);
//Execute
var success = false;
try
{
var results = pipeline.Invoke();
var actualResult = Convert.ToString(results[results.Count - 1]);
if (actualResult == "No MailBox Found")
success = false;
else
success = bool.Parse(actualResult);
}
catch (Exception ex)
{
success = false;
}
runspace.Close();
StackTrace:
$password = ConvertTo-SecureString $AccountPassword -AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential($AccountUserName,$password)
$soption = New-PSSessionOption -SkipCACheck -SkipCNCheck
$RMsession = New-PSSession -Authentication basic -Credential $cred - ConnectionUri exchangeURLGOESHERE -Configuration Microsoft.Exchange
Import-PSSession $RMsession -AllowClobber
$Return = $true
#[string[]]
#Select action
switch ($ActionType)
{
0 {
$Return = EnableDisableEAS -Username $Username -Email $Email -IsEnable $IsEnable
}
}
#Finish session
Remove-PSSession $RMsession