gpt4 book ai didi

powershell - 列出远程服务器上已安装的应用程序

转载 作者:行者123 更新时间:2023-12-03 14:33:59 25 4
gpt4 key购买 nike

我拼凑了以下脚本,其中列出了本地系统上所有已安装的应用程序并将其写入日志文件,但我不知道在使用 PSRemoteRegistry 时如何获得相同的输出,我需要的实际输入列表将是所有远程目标.

有没有人有将相同代码安装到通过 PSRemoteRegistry 提供的 cmdlet 的经验?具体来说,我需要它来枚举在键 HKLM:\Software\Microsoft\CurrentVersion\Uninstall 中找到的每个已安装应用程序的显示名称

我在进入 PSRemoteRegistry cmdlet 方面需要帮助的部分是:
Get-ChildItem 'HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall' | ForEach-Object {Log (Get-ItemProperty $_.pspath).DisplayName}
这是整个脚本:

    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**************"
}

}

最佳答案

你可以适应这样的事情:

$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')
}

关于powershell - 列出远程服务器上已安装的应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21946868/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com