Last active
August 10, 2021 14:23
-
-
Save LudovicOmarini/ee9d1a26f6bcb5b14c3e12b61c21ed20 to your computer and use it in GitHub Desktop.
Get an excel file of all softwares (x86 and x64) of computer(s) remotely.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
.SYNOPSIS | |
Get an excel file of all softwares (x86 and x64) of computer(s) remotely. | |
.DESCRIPTION | |
This script give you a list of all software installed on a remote computer. | |
You can find this list on an excel file created in the same folder of the script. | |
.EXAMPLE | |
Get list of a computer | |
.\Softwares-List-Of-Remote-Computers.ps1 -Computers DESKTOP-0123 | |
Get list of multiple computers | |
.\Softwares-List-Of-Remote-Computers.ps1 -Computers DESKTOP-0123,PRODUCTIONPC, DESKTOP0505 | |
#> | |
Param( | |
[Parameter(Mandatory=$true)][string]$Computer=$(throw "You haven't set a computer(s) name.") | |
) | |
$ErrorActionPreference= 'silentlycontinue' | |
function list_reg_to_csv ($C,$RG) | |
{ | |
$myobjs = @() | |
$RemoteRegistry = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey("LocalMachine",$C) | |
$RegKey = $RemoteRegistry.OpenSubKey($RG) | |
foreach($key in $RegKey.GetSubKeyNames()) | |
{ | |
$SubKey = $RegKey.OpenSubKey($key) | |
$myobj = "" | Select-Object DisplayName,Version,Publisher,InstallLocation,InstallDate,InstallSource,EstimatedSize,URLInfoAbout,Contact,Comments | |
$myobj.DisplayName = $SubKey.GetValue("DisplayName") | |
$myobj.Version = $SubKey.GetValue("DisplayVersion") | |
$myobj.Publisher = $SubKey.GetValue("Publisher") | |
$myobj.InstallLocation = $SubKey.GetValue("InstallLocation") | |
$myobj.InstallDate = $SubKey.GetValue("InstallDate") | |
$myobj.InstallSource = $SubKey.GetValue("InstallSource") | |
$myobj.EstimatedSize = $SubKey.GetValue("EstimatedSize") | |
$myobj.URLInfoAbout = $SubKey.GetValue("URLInfoAbout") | |
$myobj.Contact = $SubKey.GetValue("Contact") | |
$myobj.Comments = $SubKey.GetValue("Comments") | |
$myobjs += $myobj | |
} | |
return $myobjs | |
} | |
$ComputerList = $Computers -split ',' | |
foreach ($H in $ComputerList) | |
{ | |
if (-Not (Test-Connection -quiet $H)) | |
{ | |
#Error Message | |
echo "/!\ Le PC '$H' est éteint ou inaccessible /!\" | |
continue | |
} | |
else | |
{ | |
$output = @() | |
$output += list_reg_to_csv $H "SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall" | |
$output += list_reg_to_csv $H "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" | |
$currentPath = Split-Path -Path $MyInvocation.MyCommand.Definition -Parent | |
$dataTempPath = $currentPath + "\Software List - $H - temp.txt" | |
$output | Select-Object -Property DisplayName,Version | Export-Csv -Delimiter ";" -Path $dataTempPath -NoTypeInformation | |
$content = gc $dataTempPath | foreach { $_ -replace '"DisplayName";"Version"',"" } | |
sc -Path $dataTempPath -Value $content | |
$content = gc $dataTempPath | foreach { $_ -replace ';',"" } | |
sc -Path $dataTempPath -Value $content | |
$content = gc $dataTempPath | foreach { $_ -replace '""',';' } | |
sc -Path $dataTempPath -Value $content | |
$content = gc $dataTempPath | foreach { $_ -replace '"','' } | |
sc -Path $dataTempPath -Value $content | |
$content = gc $dataTempPath | Where-Object {$_} | |
sc -Path $dataTempPath -Value $content | |
$dataOutPath = $currentPath + "\Software List - $H.txt" | |
$dataCsvPath = $currentPath + "\Software List - $H.csv" | |
gc $dataTempPath| sort | get-unique > $dataOutPath | |
#Excel file creation | |
$SourcePath = $dataOutPath | |
#Excel file name | |
$DestinationPath = $currentPath + "\Software List - $H" | |
#Delimiter | |
$deleimter= ";" | |
$SourceTxt = Get-Content $SourcePath | |
$xlsxFile = $DestinationPath + ".xlsx" | |
if (Test-Path ($xlsxFile)) | |
{ | |
Remove-Item $xlsxFile | |
} | |
[threading.thread]::CurrentThread.CurrentCulture = 'fr-FR' | |
$xl=New-Object -ComObject "Excel.Application" | |
$wb=$xl.Workbooks.Add() | |
$ws=$wb.ActiveSheet | |
$xl=$True | |
$cells=$ws.Cells | |
$Content = Get-Content $SourcePath | |
$numOfRows = $Content.Length | |
$numOfColumns = $Content[0].split($deleimter).Count | |
for ($i=0; $i -lt $numOfRows ;$i++) | |
{ | |
$rowData = $Content[$i].split($deleimter) | |
for ($j=0; $j -lt $numOfColumns; $j++) | |
{ | |
$cellData = $rowData[$j] | |
$cells.item($i+1,$j+1) = $cellData | |
} | |
} | |
$xl.Cells.EntireColumn.AutoFit() | |
$wb.SaveAs($xlsxFile) | |
$wb.Close() | |
$xl.Quit() | |
#Delete temp files | |
Remove-Item $dataTempPath | |
Remove-Item $dataOutPath | |
#Return Message | |
echo "The softwares list of '$H' is available in : $currentPath" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment