Scenario:
The details of application installed on different machines need to be collected through PowerShell script in CSV file, named as computername.csv. Once the details collected, all CSV files need to be merged. While merging the file, the file name (computer name) need to be added as an additional column in merged CSV file.
This script has been created for above scenario. However this can be used to combine multiple CSV files into a single CSV file irrespective of what details you have in your files.
Get Software details:
The following PowerShell script has been used to export the list of installed software from different computers.
$paths = 'HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*', 'HKLM:\Software\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*'
Get-ItemProperty $paths | Select-Object DisplayName, DisplayVersion, Publisher, InstallDate | Export-csv -path "$env:computername.csv"
Powershell script to export installed software details in CSV file
Merge CSV files:
The following PowerShell script can be used to merge all CSV files in one. This script will insert one additional column at end with source CSV file name as cell value. Since the above script used the computer name as file name, the resulted column will have the computer name. You can quickly remove .CSV extension in Microsoft Excel using Find & Replace.
$sourcefolder = "C:\CSVfiles"
$sourcefiles = Get-ChildItem -Path $sourcefolder -Filter *.csv
$SourceFiles |
ForEach-Object {
# $fileName = $_
$output = Import-Csv -Path $_.FullName |
Add-Member -MemberType NoteProperty -Name 'Filename' -Value $_.Name -Passthru
$combinedoutput += $output
}
$combinedoutput | Export-Csv "$sourcefolder\CombinedSoftwareList.csv" -NoTypeInformation
Write-Host "Data merged to single CSV to $sourcefolder\CombinedSoftwareList.csv" -ForegroundColor Green
Related Posts:
- String Functions : UPPER, LOWER & PROPER | Microsoft Excel
- How To Join Texts Using TEXTJOIN & IF Functions | Microsoft Excel
- Basic Excel Functions you should know to make your work life easier
- Powershell – Get System up time
- Powershell – Compare hardware and software details on two computers
- Powershell Script : Retrieve AD Computers Properties
- Powershell – Add Users / Computers to AD Group