powershell - (Powershell) 文本框搜索文本
问题描述
我有一个列出机器上所有软件的文本框,但我想在它下面有一个搜索栏,让我可以从该列表中搜索东西。
最好我想在我输入时开始解析原始文本框中的项目。但如果它必须有一个搜索按钮,那也很好。
这在 powershell 中也可能不可行,不是 100% 确定的。任何建议都值得赞赏,通常我会给出我尝试过的一行代码,但实际上我在这里不知所措,不知道从哪里开始,因为我尝试过的几件事并没有远程完成我想要的。
- 编辑
$SysInfo = New-Object System.Windows.Forms.Textbox
$SysInfo.Location = New-Object System.Drawing.Point(5,5)
$SysInfo.Size = New-Object System.Drawing.Size(520,290)
$SysInfo.AutoSize = $true
$SysInfo.Multiline = $true
$SysInfo.ScrollBars = "Vertical"
$SysInfo.AcceptsReturn = $true
$SysInfo.AcceptsTab = $false
$SysInfo.WordWrap = $true
$SysInfo.Enabled = $True
$SysInfo.text = Get-WmiObject -Computer ($ComputerName) -Class Win32_Product | Select-Object -Property Name, Version |
Select-Object -Property * | Sort-Object Name |
Out-String
--EDIT 使用下面提到的 reddit 帖子。我不能让这些工作。
$Services = Get-Service | Select-object $Fields
$Services = Get-Service -ComputerName $ComputerName | Select-object $Fields
$Services = Get-WmiObject -Computer $ComputerName -Class Win32_Product | Select-Object -Property $Fields |
Select-Object -Property * | Sort-Object $Fields |
Out-String
跑步
$Services = Get-Service -Computername $ComputerName| Select-object $Fields
只拉我的机器,它不让我从其他机器上拉信息。它没有抛出任何错误或给我任何调试日志
- -解决了
Function Software-Pull {
[void][System.Reflection.Assembly]::LoadWithPartialName('presentationframework')
[xml]$XAML = @'
<Window Name="Form"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
Title="Common Software" Height="488.773" Width="797.65" Icon = "\\bconac01\ds-support\GS_IT\Tools\Test Tools (Alx)\Tool\icon.ico" ShowInTaskbar="False">
<Grid Margin="0,0,-8,-21">
<DataGrid Name="DataGrid1" HorizontalAlignment="Left" Height="368" VerticalAlignment="Top" Width="772" Margin="10,41,0,0"/>
<Label Content="Filter" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top"/>
<TextBox Name="FilterTextBox" HorizontalAlignment="Left" Height="26" Margin="78,10,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="172"/>
</Grid>
</Window>
'@
#Read XAML
$reader=(New-Object System.Xml.XmlNodeReader $xaml)
try{$Form2=[Windows.Markup.XamlReader]::Load( $reader )}
catch{Write-Host "Unable to load Windows.Markup.XamlReader. Some possible causes for this problem include: .NET Framework is missing PowerShell must be launched with PowerShell -sta, invalid XAML code was encountered."; exit}
# Store Form Objects In PowerShell
$xaml.SelectNodes("//*[@Name]") | ForEach-Object{
Set-Variable -Name ($_.Name) -Value $Form2.FindName($_.Name)
Write-host $_.Name
}
$Fields = @(
'Name'
'Version'
)
$Services = Get-WmiObject -Computer ($prebox.text + $device.text) -Class Win32_Product | Select-object -Property *
# Add Services to a datatable
$Datatable = New-Object System.Data.DataTable
[void]$Datatable.Columns.AddRange($Fields)
foreach ($Service in $Services)
{
$Array = @()
Foreach ($Field in $Fields)
{
$array += $Service.$Field
}
[void]$Datatable.Rows.Add($array)
}
#$filter = "DisplayName LIKE 'B%'"
#$Datatable.DefaultView.RowFilter = $filter
# Create a datagrid object and populate with datatable
$DataGrid1.ItemsSource = $Datatable.DefaultView
$DataGrid1.CanUserAddRows = $False
$DataGrid1.IsReadOnly = $True
$DataGrid1.GridLinesVisibility = "None"
$FilterTextBox.Add_TextChanged({
$InputText = $FilterTextBox.Text
$filter = "Name LIKE '$InputText%'"
$Datatable.DefaultView.RowFilter = $filter
$DataGrid1.ItemsSource = $Datatable.DefaultView
})
# Shows the form
$statusBar1.Text = "Done."
$Form2.Add_Shown({$Form2.Activate()})
$Form2.ShowDialog() | out-null
}
让它打开我的第二个论坛拉数据,AddRemoveProgram 似乎无法使用它,所以这会导致它冻结几秒钟以提取数据,但一切正常。
解决方案
推荐阅读
- xml - Smack:消息触发“格式不正确”异常
- javascript - 在 JSP 中的 json 数组的值之间添加空格
- angular - Angular 6:PrimeNG 选项卡视图:在选项卡面板之间移动时如何保留状态
- node.js - NPM install throws error internal/modules/cjs/loader.js:800 throw err;
- ios - Xcode 构建错误 - “函数 'sqlite3_key' 的隐式声明在 C99 中无效”
- python - 从 SEC EDGAR 文件中获取营业收入时一无所获
- javascript - 当数组尚不存在时,如何在 Redux 的 reducer 中向数组添加元素?
- pandas - 从连续刮取新的熊猫数据框填充,列名已知
- python-3.x - setup.py 包含一个外部 url:特定于平台的故障(Windows 和 Linux)
- reactjs - 不变量失败:您不应该使用
外面 使用谷歌地图 API