Powershell get installed applications and print with hostname

Hello,

I'm new to powershell and I'm trying to write a script that gets installed apps from registry (32 and 64) and print them with hostname:

$hostname = Read-Host "Enter WK name:"
cls
Invoke-Command -cn $hostname -ScriptBlock {
    Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* |  Select-Object DisplayName,DisplayVersion,InstallDate | ft
    }
Invoke-Command -cn $hostname -ScriptBlock {
    Get-ItemProperty HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* |  Select-Object DisplayName,DisplayVersion,InstallDate | ft -HideTableHeaders
    }

I can't print the machine name because it's not present on the registry key, I've tried using the code bellow but no success:

@{label="MachineName";Expression={$hostname}}

Can you guys help me?

July 21st, 2015 6:53am

Select @{N='MachineName';E={$env:ComputerName}}, ....

Free Windows Admin Tool Kit Click here and download it now
July 21st, 2015 7:13am

Forgot to mention that in the future the script will read from a Machine list and that's why I need a column with its name, after that I will load the data in a Excel file.
July 21st, 2015 7:13am

This makes more sense and is much faster:

Invoke-Command -cn $hostname -ScriptBlock {
    Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* 
    Get-ItemProperty HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* 
} |
 Select-Object PsComputerName,DisplayName, DisplayVersion, InstallDate

Free Windows Admin Tool Kit Click here and download it now
July 21st, 2015 7:26am

Forgot to mention that in the future the script will read from a Machine list and that's why I need a column with its name, after that I will load the data in a Excel file.

$computers |%{
    Invoke-Command -cn $_ -ScriptBlock {
        Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* 
        Get-ItemProperty HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* 
    } |
    Select-Object PsComputerName,DisplayName, DisplayVersion, InstallDate |
    Export-Csv software.csv

July 21st, 2015 8:02am

Really thank you sir, sorry for the delay on this one!

This answers was better for me, PSComputerName was returning empty values!

Thanks again!

Free Windows Admin Tool Kit Click here and download it now
August 14th, 2015 2:48am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics