Я использую exchange powershell в C # следующим образом:
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;
}
}
Теперь я хочу добавить предложение "where" к команде get-adpermission, например:
Get-ADPermission | where {($_.ExtendedRights -like “*Send-As*”) -and ($_.IsInherited -eq $false) -and -not ($_.User -like “NT AUTHORITY\SELF”)}
Я абсолютно не знаю, куда поместить предложение where или как определить эти аргументы в фигурных скобках.У кого-нибудь есть идея?