-1

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

bonneyt
  • 99
  • 1
  • 3
  • 9

2 Answers2

2

try this ( if I understood your goal ):

$reg1 | select @{n="Hostname";e={$hostname}},DisplayName,InstallDate
CB.
  • 58,865
  • 9
  • 159
  • 159
  • That's exactly what i was lookingg for! Thank you very much. I'm trying to mark this as the answer but i'm getting an error... i'll try again later. – bonneyt Nov 10 '14 at 15:10
  • @bonneyt No problems! Glad to help! – CB. Nov 11 '14 at 06:34
0

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
  • data from the uninstall key will be in one file with every computer. the final CSV file will be named something like Applications20141110.csv – bonneyt Nov 10 '14 at 15:17