Foreach for select statement

Welcome Forums General PowerShell Q&A Foreach for select statement

This topic contains 2 replies, has 2 voices, and was last updated by

 
Participant
3 years, 1 month ago.

  • Author
    Posts
  • #31587

    Participant
    Points: 0
    Rank: Member

    Hi,

    Can someone tell what i'm doing wrong here ?

    Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* | foreach-object {
    select @{Name="Name";Expression={Get-Item HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*}}} | where {$_.name -match "\W\{"} 
    
  • #31588

    Participant
    Points: 0
    Rank: Member

    I'm assuming you're trying to get the names of items in the uninstall list.

    Your major problem is the select statement

    select @{Name="Name";Expression={Get-Item HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*}}

    You're getting ALL of the items in the uninstall key and putting them into the name property – that's why you don't see any results

    If you just want the names try this

    Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* | select DisplayName, PSChildName

    you can then play with the regex to determine what you want to filter

  • #31589

    Participant
    Points: 0
    Rank: Member

    Thank you Richard, much appreciated.

The topic ‘Foreach for select statement’ is closed to new replies.