Exchange 2010 Powershell+;C#:如何进行WHERE查询
我在C#中使用exchange powershell,如下所示:Exchange 2010 Powershell+;C#:如何进行WHERE查询,c#,powershell,exchange-server,C#,Powershell,Exchange Server,我在C#中使用exchange powershell,如下所示: public PowershellResult GetSendAsPermissions(string TargetIdentity) { string CommandName = "get-adpermission"; Command cmd1 = new Command(CommandName); cmd1.Parameters.Add("Identity", Targ
public PowershellResult GetSendAsPermissions(string TargetIdentity)
{
string CommandName = "get-adpermission";
Command cmd1 = new Command(CommandName);
cmd1.Parameters.Add("Identity", TargetIdentity);
if (powershell.DomainController.Length > 0)
{
cmd1.Parameters.Add("DomainController", powershell.DomainController);
}
List<Command> commands = new List<Command>();
commands.Add(cmd1);
string errorMessages = string.Empty;
Collection<PSObject> commandResults = powershell.ExecutePowershellCommand(commands, out errorMessages);
PowershellResult psr = null;
if (errorMessages.Length == 0)
{
psr = new PowershellResult(true, "Successfully managed SendAs permission.", 0);
}
else
{
psr = new PowershellResult(false, string.Format("Error managing SendAs permission: {0}", errorMessages), 0);
}
return psr;
}
public Collection<PSObject> ExecutePowershellCommand(List<Command> commands, out string errorMessages)
{
errorMessages = "";
this.ps.Commands.Clear();
ps.Streams.Error.Clear();
if (commands != null)
{
foreach (Command cmd in commands)
{
this.ps.Commands.AddCommand(cmd);
}
Collection<PSObject> ret = null;
try
{
ret = this.ps.Invoke();
if (this.ps.Streams.Error.Count > 0)
{
StringBuilder stb = new StringBuilder();
foreach (ErrorRecord err in this.ps.Streams.Error)
{
if (err.Exception.Message != null)
{
stb.AppendLine(err.Exception.Message);
}
}
errorMessages = stb.ToString();
}
}
catch (Exception ex)
{
StringBuilder stb = new StringBuilder();
if (ex.Message != null)
{
stb.Append(ex.Message);
}
if (ex.InnerException != null)
{
if (ex.InnerException.Message != null)
{
stb.Append(string.Format(" {0}", ex.InnerException));
}
}
errorMessages = stb.ToString().Trim();
}
return ret;
}
else
{
return null;
}
}
Get-ADPermission | where {($_.ExtendedRights -like “*Send-As*”) -and ($_.IsInherited -eq $false) -and -not ($_.User -like “NT AUTHORITY\SELF”)}
我完全不知道把where子句放在哪里,也不知道如何在花括号中定义这些参数。有人有主意吗?我明白了
Collection<PSObject> commandResults = powershell.ExecutePowershellCommand(commands, out errorMessages);
这将(希望)为您提供一个经过筛选的comandResults
列表,其中只包含您需要的项目。你会想以某种方式把它传给打电话的人,或者对他们做些别的事情。我明白了
Collection<PSObject> commandResults = powershell.ExecutePowershellCommand(commands, out errorMessages);
这将(希望)为您提供一个经过筛选的
comandResults
列表,其中只包含您需要的项目。您可能希望以某种方式将其传递回调用者,或者对调用者执行其他操作。问题是“Value”仅属于“object”类型,因此其上没有“Contains”方法……仍然有一些异常,如PSObject不能转换为string,我猜有很多演员和检查要做…听起来你比我更适合检查!希望我的回答给了你一些提示,不过…问题是“Value”只是“object”类型,所以它没有方法“Contains”…仍然有一些异常,比如PSObject不能转换为string,我猜还有很多转换和检查要做…听起来你比我更适合检查它!希望我的回答能给你一些提示,不过。。。