andresgonz21
andresgonz21

Reputation: 23

Get an inventory of installed software

im having issues to create an inventory of software from my domain, i have this starting code i thought it will work but this code take the base specifications of the command Get-Adcomputer and if i execute the $result line alone with a out-gridView it list me my local software i dont know why i cant get listed the software of other device. Hope i explain myself and sorry for my bad english

$displayName = 'Adobe Acrobat DC (64-bit)'
$key = 'Registry::HKLM\Software\Microsoft\Windows\CurrentVersion\Uninstall'
$Appkey = Get-ChildItem -Path:$key | Where-Object {$_.GetValue('DisplayName') -eq $displayName}
$Appkey.PSChildName

$Appkey | Select-Object name | Split-Path -Parent


#$Result = @() # create an array
#We create a variable who can take all AdComputers

$computers =Get-ADComputer -Filter *

#Here we find the name of the computer, the group of a single program and when we install it
$Result = foreach ($computer in $computers){
    $nombre =  $computer.Name

    if(!(Test-Connection -ComputerName $nombre -BufferSize 16 -Count 1 -ErrorAction SilentlyContinue -Quiet)) {
        Write-Host "Conexion fallida con $nombre offline" -ForegroundColor Red
        continue  
    }
       
    try{
        
        $Name        = Get-CimInstance  Win32_product -ComputerName $nombre | Select-Object Name
        $PackageName = Get-CimInstance  Win32_product -ComputerName $nombre | Select-Object PackageName
        $InstallDate = Get-CimInstance  Win32_product -ComputerName $nombre | Select-Object InstallDate

        [PsCustomObject] @{
            ComputerName  = $Name.Name
            PackageName   = $PackageName.PackageName
            InstallDate   = $InstallDate.InstallDate
        }
        }
catch {
        Write-Warning "Error en la comunicacion con: $serverName, escaneando siguiente"   
    }
  }
#here we export to the destination file

$Result | Export-Csv -Path 'C:\temp\softin.csv' -UseCulture -NoTypeInformation

Upvotes: 2

Views: 3616

Answers (2)

js2010
js2010

Reputation: 27423

Windows powershell (5.1) only:

get-package

Upvotes: 0

Judd Davey
Judd Davey

Reputation: 349

You will need a Foreach loop:

$displayName = 'Adobe Acrobat DC (64-bit)'
$key = 'Registry::HKLM\Software\Microsoft\Windows\CurrentVersion\Uninstall'
$Appkey = Get-ChildItem -Path:$key | Where-Object {$_.GetValue('DisplayName') -eq $displayName}
$Appkey.PSChildName

$Appkey | Select-Object name | Split-Path -Parent


$Result = @() # create an array
#We create a variable who can take all AdComputers

$computers =Get-ADComputer -Filter *

#Here we find the name of the computer, the group of a single program and when we install it
$Result = foreach ($computer in $computers)
{
    $Ping = Test-Connection $computer.samaccountname -Count 1 -Quiet
    if ($Ping)
    {
        Write-Host "Computer Found: $($computer.samaccountname)" -ForegroundColor Green
        get-ciminstance win32_product -ComputerName $computer.Samaccountname | Select-object Name, PackageName, InstallDate
    }
    else
    {
        Write-Host "Computer NOT Found: $($computer.samaccountname)" -ForegroundColor Red
    }

}

#here we export to the destination file

$Result | Export-Csv -Path 'C:\temp\softin.csv' -UseCulture -NoTypeInformation

Upvotes: 1

Related Questions