manipulate (add text) to CMDLET output

180 views Asked by At

I've beat my head against the wall for a few days trying to figure this one out.. I'm trying to take the output of the following command, export it as a CSV with the hostname at the beginning of each line

$reg1 = Get-ItemProperty HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* | Where {$_.DisplayName -ne $null }
$reg1 | select DisplayName,InstallDate

the final CSV output would look something like this, but for each item in the uninstall key

Office_Computer,PuTTY version 0.63,20140319

I have tried doing a foreach-object by first selecting the fields i want to see, then doing a foreach on the new array

$test = $reg1 | select DisplayName,Installdate
$test | foreach-object {"$hostname,$_"}

that works, but the output isn't in a nice table like before... it looks like this

PDMZ-SUPT1,@{DisplayName=PuTTY version 0.63; InstallDate=20140319}

i suppose what i'm looking for is a custom object, but i have no idea how to make that work. Oh, and in case you are wondering, this command will be run on multiple computers to build a single file of "installed applications". To know which computer has what software installed, the hostname is added.

Thanks

2

There are 2 answers

2
CB. On BEST ANSWER

try this ( if I understood your goal ):

$reg1 | select @{n="Hostname";e={$hostname}},DisplayName,InstallDate
1
AudioBubble On

Wouldn't it be enough to name the file after the host? Or do you have to inlcude all items from all hosts into one CSV file?

Get-ItemProperty HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* | where DisplayName | 
    select DisplayName, InstallDate | Export-Csv "$(hostname).csv" -NoTypeInformation