Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Winforms 将cmdlet的详细信息输出到GUI文本框Powershell_Winforms_Powershell_User Interface_Scripting_Automation - Fatal编程技术网

Winforms 将cmdlet的详细信息输出到GUI文本框Powershell

Winforms 将cmdlet的详细信息输出到GUI文本框Powershell,winforms,powershell,user-interface,scripting,automation,Winforms,Powershell,User Interface,Scripting,Automation,假设我有一个表单,有一个按钮和一个文本框。按钮所做的只是使用复制项。如何将该副本的输出输出到文本框中?更进一步,我希望它能像我在看控制台一样实时运行。如果不可能,那么在执行命令后更新文本框也可以 例如: function CreateFormButton ( $locationheight, $locationwidth, $sizeheight, $sizewidth, $fieldname, $functionname ) { $Button = New-Object System.Wi

假设我有一个表单,有一个按钮和一个文本框。按钮所做的只是使用复制项。如何将该副本的输出输出到文本框中?更进一步,我希望它能像我在看控制台一样实时运行。如果不可能,那么在执行命令后更新文本框也可以

例如:

function CreateFormButton ( $locationheight, $locationwidth, $sizeheight, $sizewidth, $fieldname, $functionname ) {
  $Button = New-Object System.Windows.Forms.Button 
  $Button.Location = New-Object System.Drawing.Size($locationheight, $locationwidth) 
  $Button.Size = New-Object System.Drawing.Size($sizeheight, $sizewidth) 
  $Button.Text = $fieldname 
  $Button.Add_Click( $functionname ) 
  $Form.Controls.Add($Button) 
}

function CreateTextWindow ( $locationHeight, $LocationWidth, $TextBoxHeight, $TextBoxWidth, $name ) {
  $TextWindow = new-object System.Windows.Forms.TextBox
  $TextWindow.Size = New-Object System.Drawing.Size($textBoxHeight,$textBoxWidth)
  $TextWindow.location = new-object system.drawing.point($locationHeight,$LocationWidth)
  #$textWindow.Text = "Complete"
  $TextWindow.Name = $name
  $TextWindow.Multiline = $true
  $Form.Controls.Add($TextWindow) 
}

$path1 = "C:\SomePath\"
$path2 = "C:\SomePath\"

function call_Clean
{
  #Edit
  #Copy-Item "$Path1\Unit" -Destination $Path2 -Recurse -Force  
  Copy-Item "$Path1\Unit" -Destination $Path2 -Recurse -Force -Verbose
}

$Form = New-Object system.Windows.Forms.Form
$Form.Text = "Tool"
$Form.Size = New-Object System.Drawing.Size (475, 600)
$Form.Location = New-Object System.Drawing.Point(4000, 300)



CreateFormButton 315 100 120 40 'Local Deploy' ${function:call_Clean}
CreateTextWindow 150 160 300 375 'TextBox'
Copy-Item C:\myfolder\myfile.txt -Destination C:\myfolder2\myfile.txt
$result = Test-Path C:\myfolder2\myfile.txt
if($result)
{
    $MyTextBox.Text = "Item moved"
}
Else
{
    $MyTextBox.Text = "Item failed to move"
}

复制项
不返回任何值。复制项目后,您希望执行的操作是
测试路径
。然后,您可以根据
测试路径返回的True或False在文本框中设置自定义值

例如:

function CreateFormButton ( $locationheight, $locationwidth, $sizeheight, $sizewidth, $fieldname, $functionname ) {
  $Button = New-Object System.Windows.Forms.Button 
  $Button.Location = New-Object System.Drawing.Size($locationheight, $locationwidth) 
  $Button.Size = New-Object System.Drawing.Size($sizeheight, $sizewidth) 
  $Button.Text = $fieldname 
  $Button.Add_Click( $functionname ) 
  $Form.Controls.Add($Button) 
}

function CreateTextWindow ( $locationHeight, $LocationWidth, $TextBoxHeight, $TextBoxWidth, $name ) {
  $TextWindow = new-object System.Windows.Forms.TextBox
  $TextWindow.Size = New-Object System.Drawing.Size($textBoxHeight,$textBoxWidth)
  $TextWindow.location = new-object system.drawing.point($locationHeight,$LocationWidth)
  #$textWindow.Text = "Complete"
  $TextWindow.Name = $name
  $TextWindow.Multiline = $true
  $Form.Controls.Add($TextWindow) 
}

$path1 = "C:\SomePath\"
$path2 = "C:\SomePath\"

function call_Clean
{
  #Edit
  #Copy-Item "$Path1\Unit" -Destination $Path2 -Recurse -Force  
  Copy-Item "$Path1\Unit" -Destination $Path2 -Recurse -Force -Verbose
}

$Form = New-Object system.Windows.Forms.Form
$Form.Text = "Tool"
$Form.Size = New-Object System.Drawing.Size (475, 600)
$Form.Location = New-Object System.Drawing.Point(4000, 300)



CreateFormButton 315 100 120 40 'Local Deploy' ${function:call_Clean}
CreateTextWindow 150 160 300 375 'TextBox'
Copy-Item C:\myfolder\myfile.txt -Destination C:\myfolder2\myfile.txt
$result = Test-Path C:\myfolder2\myfile.txt
if($result)
{
    $MyTextBox.Text = "Item moved"
}
Else
{
    $MyTextBox.Text = "Item failed to move"
}

您还可以添加
-PassThru
并将该响应分配给一个变量。

我没有将-verbose标志添加到复制项语句中,我道歉。我将对其进行编辑,但基本上我正在寻找-verbose标志将提供的输出,以写入文本框。