Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Powershell 列出远程服务器上安装的应用程序_Powershell - Fatal编程技术网

Powershell 列出远程服务器上安装的应用程序

Powershell 列出远程服务器上安装的应用程序,powershell,Powershell,我拼凑了以下脚本,其中列出了本地系统上所有已安装的应用程序,并将其写入日志文件,但我不知道在使用PSRemoteRegistry时如何获得相同的输出,我需要的实际输入列表将是所有远程目标 是否有人有将相同的代码安装到PSRemoteRegistry提供的cmdlet中的经验?具体来说,我需要它枚举在HKLM:\Software\Microsoft\CurrentVersion\Uninstall项中找到的每个已安装应用程序的显示名 我在进入PSRemoteRegistry cmdlet方面需要的

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

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

我在进入PSRemoteRegistry cmdlet方面需要的帮助是:

Get-ChildItem'HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall'| ForEach对象{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')
}

你见过调用命令吗

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

}

为什么不使用PowerShell远程处理部署脚本,并在主机会话中返回结果?我建议从函数返回对象,而不是将文本写入日志文件。这将帮助您更有效地处理结果。我唯一的问题是我们讨论的是26个域和3000多个服务器。我不能依靠主机级别的手动配置修改来适应脚本的执行。PowerShell远程处理是否需要触摸每一个以确保PowerShell和正确的配置在目标系统上就位?