VB.NET - PS 管道 - 响应错误
VB.NET - PS Pipeline - Responding to error
我正在 vb.net 应用程序中执行 PS 命令,PS 命令需要回答 'Yes' 或 'No' 才能继续。
下面显示的是我的命令管道代码:
Command.AddCommand("Set-MailboxAutoReplyConfiguration").AddParameter("Identity", username).AddParameter("AutoReplyState", "Scheduled").AddParameter("StartTime", Format(FWDStart, "yyyy-MM-dd HH:mm:ss")).AddParameter("EndTime", Format(FWDEnd, "yyyy-MM-dd HH:mm:ss")).AddParameter("InternalMessage", message)
这就是我为响应异常而尝试的方法:
Try
results = pipeline.Invoke()
Catch ex As Exception
Dim messageresponse As Integer = MessageBox.Show(ex.Message, "User Information", MessageBoxButtons.YesNo, MessageBoxIcon.Error)
If messageresponse = DialogResult.Yes Then
pipeline.AddScript("Yes")
ElseIf messageresponse = DialogResult.No Then
pipeline.AddCommand("No")
End If
Try
pipeline.Invoke()
Catch ex2 As Exception
MessageBox.Show(ex.Message, "User Information", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Try
对于 messageresponse
IF
语句,我确实尝试了 pipeline.AddCommand
/.AddScript
/.AddParamater
,但这没有用。
异常错误有这条消息:"A command that prompts the user has failed because the host program or the command type does not support user interaction."
我尝试了第一条评论中提供的 .AddParameter("Confirm", false) 解决方案,但没有奏效。
该错误是由于在交换中设置了 ForwardingSMTPAddress 引起的,因为这是通过管理门户设置不在办公室时设置的。我们现在想通过我们的应用程序设置它,这将在 ForwardingAddress 字段中设置它。
MS 文档 (https://docs.microsoft.com/en-us/powershell/module/exchange/mailboxes/set-mailboxautoreplyconfiguration?view=exchange-ps) 显示 -Confirm
参数可用于绕过使用 -Confirm:$false
的确认提示。我假设您应该能够执行以下操作:
Command.AddCommand("Set-MailboxAutoReplyConfiguration").AddParameter("Identity", username).AddParameter("AutoReplyState", "Scheduled").AddParameter("StartTime", Format(FWDStart, "yyyy-MM-dd HH:mm:ss")).AddParameter("EndTime", Format(FWDEnd, "yyyy-MM-dd HH:mm:ss")).AddParameter("InternalMessage", message).AddParameter("Confirm", false)
我正在 vb.net 应用程序中执行 PS 命令,PS 命令需要回答 'Yes' 或 'No' 才能继续。
下面显示的是我的命令管道代码:
Command.AddCommand("Set-MailboxAutoReplyConfiguration").AddParameter("Identity", username).AddParameter("AutoReplyState", "Scheduled").AddParameter("StartTime", Format(FWDStart, "yyyy-MM-dd HH:mm:ss")).AddParameter("EndTime", Format(FWDEnd, "yyyy-MM-dd HH:mm:ss")).AddParameter("InternalMessage", message)
这就是我为响应异常而尝试的方法:
Try
results = pipeline.Invoke()
Catch ex As Exception
Dim messageresponse As Integer = MessageBox.Show(ex.Message, "User Information", MessageBoxButtons.YesNo, MessageBoxIcon.Error)
If messageresponse = DialogResult.Yes Then
pipeline.AddScript("Yes")
ElseIf messageresponse = DialogResult.No Then
pipeline.AddCommand("No")
End If
Try
pipeline.Invoke()
Catch ex2 As Exception
MessageBox.Show(ex.Message, "User Information", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Try
对于 messageresponse
IF
语句,我确实尝试了 pipeline.AddCommand
/.AddScript
/.AddParamater
,但这没有用。
异常错误有这条消息:"A command that prompts the user has failed because the host program or the command type does not support user interaction."
我尝试了第一条评论中提供的 .AddParameter("Confirm", false) 解决方案,但没有奏效。
该错误是由于在交换中设置了 ForwardingSMTPAddress 引起的,因为这是通过管理门户设置不在办公室时设置的。我们现在想通过我们的应用程序设置它,这将在 ForwardingAddress 字段中设置它。
MS 文档 (https://docs.microsoft.com/en-us/powershell/module/exchange/mailboxes/set-mailboxautoreplyconfiguration?view=exchange-ps) 显示 -Confirm
参数可用于绕过使用 -Confirm:$false
的确认提示。我假设您应该能够执行以下操作:
Command.AddCommand("Set-MailboxAutoReplyConfiguration").AddParameter("Identity", username).AddParameter("AutoReplyState", "Scheduled").AddParameter("StartTime", Format(FWDStart, "yyyy-MM-dd HH:mm:ss")).AddParameter("EndTime", Format(FWDEnd, "yyyy-MM-dd HH:mm:ss")).AddParameter("InternalMessage", message).AddParameter("Confirm", false)