我对 Windows 窗体很陌生,所以请记住这一点。我确实花了很多时间搜索和寻找答案(在提问之前应该这样做)。
所以我的问题是我正在尝试将 Powershell 结果输出显示到文本框中。我的脚本有单选按钮,提供检查用户 AD 帐户状态、解锁帐户、禁用等选项。他们在“groupbox”中选择收音机,然后点击开始按钮。然后我想将命令输出显示到文本框。例如,我应该能够将 Get-Aduser 过滤的结果显示到文本框。
这是我的结束函数的一个例子(我还没有向它添加所有未来的单选按钮):
Function StartOptions
{
$User=$InputBox.text
If ($Domain1Button.checked -eq $true) {$Domain = "Domain1"}
If ($Domain2Button.checked -eq $true) {$Domain = "Domain2"}
If ($UserStatusButton.checked -eq $true) {Get-ADUser -identity $User -Server $Domain -Properties * | Select-Object SamAccountName,Name,LockedOut,Enabled,EmailAddress,PasswordLastSet|Format-Table}
$outputBox.Text= (Not sure what to put here to Output the results of Aduser)
}
Groupbox 的一个例子:
#GROUPBOX Domain Selection
$groupBox1 = New-Object System.Windows.Forms.GroupBox
$groupBox1.Location = New-Object System.Drawing.Size(20,90)
$groupBox1.size = New-Object System.Drawing.Size(175,37)
$groupBox1.text = "Choose a Domain:"
$Form.Controls.Add($groupBox1)
单选按钮示例:
$Domain1Button= New-Object System.Windows.Forms.RadioButton
$Domain1Button.Location = '15,15'
$Domain1Button.size = '72,20'
$Domain1Button.Checked = $true
$Domain1Button.Text = "Domain1"
$groupBox1.Controls.Add($Domain1Button)
如果这是一个愚蠢的问题,请原谅我。我真的在努力学习。
太感谢了。
根据我上面的评论...
这个用例在网络和Youtube 上有很多例子,因为它很常见,早在 PowerShell 出现之前。这就是了解和使用“表单事件”的全部内容。
$buttonComputerName_Click = {
$textboxResults.Text = $env:ComputerName
}
要么
MS powershellgallery.com 中有一些模块,用于构建 WinForm/WPF GUI 的...
Find-Module -Name '*gui*'
Find-Module -Name '*form*'
...只需安装和使用它们。
还有,这个免费的 PowerShell GUI 开发网站。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句