[英]Powershell: Filtering unwanted values from get-wmiobject win32_product
I'm trying to get the list of installed applications on a machine into a Listbox and so far I have this: 我正在尝试将计算机上已安装的应用程序列表放到列表框中,到目前为止,我有以下内容:
function programsinstalled_current
{
$prog = get-wmiobject win32_product -computer summer -Property Name | select Name
foreach($program in $prog)
{
[Void]$program_list_current.items.add($program)
}
}
and it returns this in the list box: 并在列表框中返回:
My question is how do I get rid of the unwanted '@{name=' at the start of each program name and the '}' at the end of each name? 我的问题是如何消除每个程序名称开头的不必要的'@ {name ='和每个名称结尾的'}'?
I've tried the below code with getting the AD groups of a machine into Listbox and it works fine, but the same syntax won't work the get-wmiobject win32_product
: 我已经尝试将下面的代码与将机器的AD组放入Listbox一起使用,并且工作正常,但是相同的语法对
get-wmiobject win32_product
:
function fill_current_list
{
$processnames_t = (Get-ADComputer -Identity $current_hostname.text -Property MemberOf).MemberOf
foreach ($processname in $processnames_t)
{
[void]$AD_list_current.Items.Add($processname)
}
If possible, I'd rather not use -replace
如果可能的话,我宁愿不使用
-replace
Thanks 谢谢
尝试:
[Void]$program_list_current.items.add($program.name)
You could also add all product names without looping on them: 您还可以添加所有产品名称而无需在其上循环:
$prog = gwmi win32_product -computer summer -Property Name | select -expand Name
$program_list_current.items.AddRange($prog)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.