List of installed applications on remote servers

I have compiled the following script that lists all installed applications on the local system and writes them to a log file, but I don’t know how to get the same result when using PSRemoteRegistry, the actual input list I need will be all deleted targets.

Does anyone have experience installing the same code in cmdlets available through PSRemoteRegistry? In particular, I need to list the display name of each installed application found in the HKLM key: \ Software \ Microsoft \ CurrentVersion \ Uninstall

I need help with PSRemoteRegistry cmdlets:

Get-ChildItem 'HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall' | ForEach-Object {Log (Get-ItemProperty $_.pspath).DisplayName}

and this is the whole script:

    clear
    #$ErrorActionPreference = "silentlycontinue"

    $Logfile = "C:\temp\installed_apps.log"

    Function Log
    {
        param([string]$logstring)

        Add-Content $Logfile -Value $logstring
    }

    $target_list = Get-Content -Path c:\temp\installed_apps_targets.txt

    foreach ($system in $target_list){

        if (test-connection $system -quiet) 
        {
           Log "---------------Begin $system---------------"
           Get-ChildItem 'HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall' | ForEach-Object {Log (Get-ItemProperty $_.pspath).DisplayName}
           Log "---------------End $system---------------"
        }
        else 
        {
            Log "**************$system was unreachable**************"
        }

}
+4
source share
2 answers

- :

$Computer = "ComputerName"

$Reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', $Computer)
$RegKey= $Reg.OpenSubKey('Software\Microsoft\Windows\CurrentVersion\Uninstall')

$Keys = $RegKey.GetSubKeyNames()

$Keys | ForEach-Object {
   $Subkey = $RegKey.OpenSubKey("$_")
   Write-Host $Subkey.GetValue('DisplayName')
}
+1

Invoke-Command?

$Logfile = "C:\temp\installed_apps.log"

Function Log() {
    param([string]$logstring)

    Add-Content $Logfile -Value $logstring
}

$scriptbock = {Get-ChildItem 'HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall' | ForEach-Object {Log (Get-ItemProperty $_.pspath).DisplayName}}

Get-Content -Path c:\temp\installed_apps_targets.txt | % {
    if (test-connection $_ -quiet) {
       Log "---------------Begin $system---------------"
       Log $(Invoke-Command -ComputerName $_ -ScriptBlock $scriptblock)
       Log "---------------End $system---------------"
    }
    else 
    {
        Log "**************$system was unreachable**************"
    }

}
+1

Source: https://habr.com/ru/post/1528210/


All Articles