1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
| <# : Batch Script Section
@rem # The previous line does nothing in Batch, but begins a multiline comment block in PowerShell. This allows a single script to be executed by both interpreters.
@echo off
Title Get-InstalledApplications & Color 1B
@REM OPEN CMD WINDOW MAXIMIZED
IF NOT "%1"=="MAX" START /MAX CMD /D /C "%~0" MAX & GOTO :EOF
cd "%~dp0"
echo( & Echo(
Echo( Please Wait ... Loading script is in Progress ...
Powershell -executionpolicy bypass -Command "Invoke-Expression $([System.IO.File]::ReadAllText('%~f0'))"
EndLocal
pause
goto:eof
#>
# Powershell Script Section begin here...
# Here we execute our powershell commands...
cls
$ErrorActionPreference = 'Stop'
$InstalledApplications = "$Env:userprofile\desktop\InstalledApplications.txt"
if (Test-Path $InstalledApplications) {Remove-Item $InstalledApplications}
$Error_Log = "$Env:userprofile\desktop\Error_Log.txt"
$registry32 = "HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall"
$registry64 = "HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall"
function Get-InstalledApplications {
try {
$applications32 = Get-ItemProperty $registry32\* -ErrorVariable error -ErrorAction Stop | Select-Object DisplayName, DisplayVersion, Publisher, InstallDate
$applications32 | Out-File -FilePath $InstalledApplications -Encoding UTF8 -Append
$applications32 | Format-Table
} catch {
# Code to handle the exception
$ErrorMessage = $_.Exception.Message
$Timestamp = (Get-Date -Format "yyyy-MM-dd HH:mm:ss")
$ErrorDetails = "$Timestamp - Error occurred in Get-InstalledApplications function. Error Message: $ErrorMessage"
Add-Content -Path $Error_Log -Value $ErrorDetails -ErrorAction 'Continue'
}
try {
$applications64 = Get-ItemProperty $registry64\* -ErrorVariable error -ErrorAction Stop | Select-Object DisplayName, DisplayVersion, Publisher, InstallDate
$applications64 | Out-File -FilePath $InstalledApplications -Encoding UTF8 -Append
$applications64 | Format-Table
} catch {
# Code to handle the exception
$ErrorMessage = $_.Exception.Message
$Timestamp = (Get-Date -Format "yyyy-MM-dd HH:mm:ss")
$ErrorDetails = "$Timestamp - Error occurred in Get-InstalledApplications function. Error Message: $ErrorMessage"
Add-Content -Path $Error_Log -Value $ErrorDetails -ErrorAction 'Continue'
}
}
Get-InstalledApplications
if (Test-Path $InstalledApplications) {ii $InstalledApplications} |