List fo sofware installed in the machine through Powershell - Knowledgebase - CLOUDRAIN

List fo sofware installed in the machine through Powershell Print

  • 0

# Function to get installed software information
function Get-InstalledSoftware {
# Paths to registry keys containing installed software information
$registryPaths = @(
"HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall",
"HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall"
)

$softwareList = @()
$computerName = $env:COMPUTERNAME
$username = $env:USERNAME

foreach ($path in $registryPaths) {
# Get all subkeys under each registry path
$subkeys = Get-ChildItem -Path $path

foreach ($subkey in $subkeys) {
$software = Get-ItemProperty -Path $subkey.PSPath

# Collect software details
$name = $software.DisplayName
$version = $software.DisplayVersion
$installDate = $software.InstallDate
$publisher = $software.Publisher

# Convert install date to a readable format if available
if ($installDate -and $installDate -match '^\d{8}$') {
try {
$installDate = [datetime]::ParseExact($installDate, 'yyyyMMdd', $null).ToString('yyyy-MM-dd')
} catch {
$installDate = "Invalid Date"
}
} else {
$installDate = "Unknown"
}

# Add software information to the list if a name is found
if ($name) {
$softwareList += [PSCustomObject]@{
ComputerName = $computerName
Username = $username
Name = $name
Version = $version
InstallDate = $installDate
Publisher = $publisher
}
}
}
}

# Output the collected software information
return $softwareList
}

# Get the installed software list
$installedSoftware = Get-InstalledSoftware

# Define the output folder path
$outputFolderPath = "C:\Path\To\Output"

# Ensure the output folder exists
if (-not (Test-Path -Path $outputFolderPath)) {
New-Item -Path $outputFolderPath -ItemType Directory | Out-Null
}

# Construct the CSV file path using the computer name
$outputCsvPath = Join-Path -Path $outputFolderPath -ChildPath "$($env:COMPUTERNAME)_InstalledSoftware.csv"

# Export the results to a CSV file
$installedSoftware | Export-Csv -Path $outputCsvPath -NoTypeInformation

# Azure Blob Storage details
$storageAccountName = ""
$storageAccountKey = ""
$containerName = ""
$blobName = "$($env:COMPUTERNAME)_InstalledSoftware.csv"


# Connect to Azure Storage
$context = New-AzStorageContext -StorageAccountName $storageAccountName -StorageAccountKey $storageAccountKey

# Construct the blob name using the file name
$blobName = [System.IO.Path]::GetFileName($outputCsvPath)

# Upload the file to Azure Blob Storage
Set-AzStorageBlobContent -File $outputCsvPath -Container $containerName -Blob $blobName -Context $context -Force

# Display a message indicating the file has been uploaded
Write-Output "Installed software information exported to $outputCsvPath and uploaded to Azure Blob Storage container '$containerName' as '$blobName'"


Was this answer helpful?

« Back

Powered by WHMCompleteSolution