Filter out blanks

Welcome Forums General PowerShell Q&A Filter out blanks

This topic contains 0 replies, has 1 voice, and was last updated by  Forums Archives 7 years ago.

  • Author
    Posts
  • #5755

    Member
    Points: 0
    Rank: Member

    by Lery at 2013-04-03 09:22:17

    Hello everyone and thank you very much for taking the time to read my post. Here is the code I'm currently using.

    Get-ChildItem -Path HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall |

    Get-ItemProperty |

    Select-Object -Property DisplayName

    It works great. However, when it runs it has plenty of blank spaces in the output. Is there a way to "filter" out these blank spaces so everything is nicely together in its own row?

    Here is what the output looks like

    by mjolinor at 2013-04-03 09:42:15

    One way:

    Get-ChildItem -Path HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall |

    Get-ItemProperty |

    Select-Object -Property DisplayName | where {$_.DisplayName}

    by Lery at 2013-04-03 10:16:35

    One way:

    Get-ChildItem -Path HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall |

    Get-ItemProperty |

    Select-Object -Property DisplayName | where {$_.DisplayName}

    Very good thank you. If I can ask a follow-up question? There is an InstallDate entry in the key that I can get. My code now becomes this:

    Get-ChildItem -Path HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall | Get-ItemProperty | Select-Object -Property DisplayName, installdate. | where {$_.DisplayName}

    It works, but the installdate is returned in the following format: 20121108

    Is there a way to convert that to say: 11-08-2012?

    by ArtB0514 at 2013-04-03 10:57:01

    Not very pretty, but this should work:

    Get-ChildItem -Path HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall | Get-ItemProperty | Where {$_.DisplayName} | Select-Object DisplayName, @{Name='Installed';Expression={"$($_.installdate.Substring(4,2))-$($_.installdate.Substring(6,2))-$($_.installdate.Substring(0,4))"}}

    Note that I moved the Where clause to before the Select clause because that will reduce the number of objects that Select will have to process.

    by Lery at 2013-04-03 12:10:29

    Not very pretty, but this should work:

    Get-ChildItem -Path HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall | Get-ItemProperty | Where {$_.DisplayName} | Select-Object DisplayName, @{Name='Installed';Expression={"$($_.installdate.Substring(4,2))-$($_.installdate.Substring(6,2))-$($_.installdate.Substring(0,4))"}}

    Note that I moved the Where clause to before the Select clause because that will reduce the number of objects that Select will have to process.

    Thank you, this worked perfectly.

The topic ‘Filter out blanks’ is closed to new replies.