2

I have a PowerShell Script that I like to run with a Visual Interface (GUI - with Windows Form elements) Everything is working so far but I have one big problem:

Is it possible to display the command pane from PowerShell on the created Windows Form? For Example: In one part of my PowerShell Script I am running the following command:

Upgrade-SPContentDatabase DBName

This command requires to confirm some messages with "Yes/No" that will be normally displayed in the command pane from PowerShell... Can this be done over the Windows Form so that I can hide the PowerShell-Script Window in the background?

Or is there any other way to display it in a new window that comes up?

Screenshot: enter image description here

Any Ideas?

4

1 回答 1

0

A messagebox(GUI) 不同于提示。只要您在 powershell 控制台(不是 ISE)中运行脚本,就会在控制台中显示提示。(可能有一个设置可以让它们像 ISE 中一样使用 GUI)。一种解决方法是尝试禁用脚本中的确认提示,然后messagebox自己创建一个。

在按钮的点击处理程序中尝试以下操作:

$handler_button1_Click= 
{
    $n = [System.Windows.Forms.MessageBox]::Show("Are you sure?", "Confirm", [System.Windows.Forms.MessageBoxButtons]::YesNo)
    if ($n -eq "Yes") {
        #Ignore confirm dialogs with -Confirm:$false
        Upgrade-SPContentDatabase DBName -Confirm:$false
    }
}
于 2013-05-26T18:55:48.643 回答