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?
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
:
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
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)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.