mirror of
https://gitlab.com/JKANetwork/powerfulcomputermanager.git
synced 2026-02-18 03:01:31 +01:00
76 lines
2.6 KiB
PowerShell
76 lines
2.6 KiB
PowerShell
$root = $PSCommandPath | Split-Path -Parent
|
|
. $root\config.ps1
|
|
|
|
$table = (Invoke-RestMethod -Method Get -Uri "$server/get/computers") # Get all computers
|
|
$DNSPrefix = (get-DnsClientGlobalSetting).SuffixSearchList[0] # Get DNS Prefix, needed to search computers in some environments
|
|
|
|
|
|
$array = @()
|
|
|
|
function getPrograms($computername) {
|
|
|
|
|
|
#Define the variable to hold the location of Currently Installed Programs
|
|
|
|
$UninstallKey="SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall"
|
|
|
|
#Create an instance of the Registry Object and open the HKLM base key
|
|
|
|
$reg=[microsoft.win32.registrykey]::OpenRemoteBaseKey('LocalMachine',$computername)
|
|
|
|
#Drill down into the Uninstall key using the OpenSubKey Method
|
|
|
|
$regkey=$reg.OpenSubKey($UninstallKey)
|
|
|
|
#Retrieve an array of string that contain all the subkey names
|
|
|
|
$subkeys=$regkey.GetSubKeyNames()
|
|
|
|
#Open each Subkey and use GetValue Method to return the required values for each
|
|
|
|
$allprogs = @()
|
|
|
|
foreach($key in $subkeys){
|
|
|
|
$thisKey=$UninstallKey+"\\"+$key
|
|
|
|
$thisSubKey=$reg.OpenSubKey($thisKey)
|
|
|
|
$obj = New-Object PSObject
|
|
|
|
$obj | Add-Member -MemberType NoteProperty -Name "ComputerName" -Value $computername
|
|
|
|
$obj | Add-Member -MemberType NoteProperty -Name "DisplayName" -Value $($thisSubKey.GetValue("DisplayName"))
|
|
|
|
$obj | Add-Member -MemberType NoteProperty -Name "DisplayVersion" -Value $($thisSubKey.GetValue("DisplayVersion"))
|
|
|
|
$obj | Add-Member -MemberType NoteProperty -Name "InstallLocation" -Value $($thisSubKey.GetValue("InstallLocation"))
|
|
|
|
$obj | Add-Member -MemberType NoteProperty -Name "Publisher" -Value $($thisSubKey.GetValue("Publisher"))
|
|
|
|
|
|
$allprogs += $obj
|
|
|
|
}
|
|
|
|
return $allprogs
|
|
}
|
|
|
|
|
|
foreach ($comp in $table){
|
|
$name = -join($comp.Name,".",$DNSPrefix);
|
|
if (Test-Connection -ComputerName $name -Quiet){
|
|
Write-Output $name
|
|
$array += getPrograms($name)
|
|
}else{
|
|
Write-Output "$name Offline"
|
|
}
|
|
|
|
}
|
|
|
|
#$array | Where-Object { $_.DisplayName } | select ComputerName, DisplayName, DisplayVersion, Publisher | ft -auto
|
|
|
|
$array | Where-Object { $_.DisplayName } | select ComputerName, DisplayName, DisplayVersion | export-csv "$PSScriptRoot\..\Reports\software.csv" -NoTypeInformation -Delimiter ";" -Encoding ASCII
|
|
Write-Host "Guardado en ..\Reports\software.csv"
|
|
#$content = [System.IO.File]::ReadAllText("$PSScriptRoot\Reports\software.csv").Replace("A","")
|
|
#[System.IO.File]::WriteAllText("$PSScriptRoot\Reports\software.csv", $content) |