【发布时间】:2020-04-27 15:10:17
【问题描述】:
我在 C# 中运行 Powershell 命令来获取邮箱交换文件夹委托。
我正在使用以下 2 个命令:
string scriptText = "Get-MailboxFolderPermission -Identity \"" + email + ":\\calendar\" | ? { ($_.user.tostring() -notlike \"Anonymous\") -and ($_.user.tostring() -notlike \"Default\") } | select User, AccessRights"
using (var powerShell = PowerShell.Create()) {
powerShell.AddScript(scriptText);
powerShell.Runspace = Runspace;
var iAsyncResult = powerShell.BeginInvoke();
psData = powerShell.EndInvoke(iAsyncResult);
}
string scriptText = "Get-MailboxPermission -Identity " + email + " | ? {($_.user.tostring() -ne “NT AUTHORITY\\SELF”) –and ($_.user.tostring() -ne “DOMAINDiscovery Management”) -and $_.IsInherited -eq $false -and ($_.AccessRights -match \"" + accessRights + "\")} | select User, AccessRights";
using (var powerShell = PowerShell.Create()) {
powerShell.AddScript(scriptText);
powerShell.Runspace = Runspace;
var iAsyncResult = powerShell.BeginInvoke();
psData = powerShell.EndInvoke(iAsyncResult);
}
在随机间隔我得到以下异常: hostexception:提示用户失败的命令,因为宿主程序或命令类型不支持用户交互。主机试图通过以下消息请求确认:输入您的凭据
我的命令中没有用户提示或任何内容。有谁知道为什么我的脚本失败了?
【问题讨论】:
-
您是否正在查找您无权访问的帐户信息
-
我拥有跨域邮箱的超级用户访问权限
-
使用 try catch 语句捕获引发错误的帐户,然后找出该帐户的不同之处。
-
我捕获了异常,关闭了运行空间,将其处理掉,然后在我得到异常时重新连接。然后,我可以访问在收到异常之前无法访问的邮箱。所以我不认为这是一个访问的东西。
-
事实证明,当我直接从 PowerShell 运行它时,我得到一个隐含的远程错误。然后它会提示输入用户名/密码。这一定是在 C# 的幕后发生的,它作为原始错误报告给我。我不确定如何处理隐式远程错误。
标签: c# powershell