首页 > 解决方案 > 我的远程注册表查找器中的 Powershell 机器名称未输出到文本文件

问题描述

如果在用户安装中找到程序,我正在尝试将机器名称复制到文本文件

机器正在复制到文本文件,但是它正在获取未安装的机器

$computers = Get-Content C:\temp\MY_TEST.txt | ForEach-Object {$_.trim()}
foreach($computer in $computers) {

Invoke-command -computername $computer {

$UserHives = Get-ChildItem Registry::HKEY_USERS\ | Where-Object {$_.Name -match '^HKEY_USERS\\S-1-5-[\d\-]+$'}

foreach($Hive in $UserHives)
{
# Construct path from base key
$Path = Join-Path $Hive.PSPath "Software\Microsoft\Windows\CurrentVersion\Uninstall\*"

# Attempt to retrieve Item property
$one = Get-ItemProperty -Path $Path -ErrorAction SilentlyContinue | Where-Object {$_.displayname -eq 'ABC'}
$two = Get-ItemProperty -Path $Path -ErrorAction SilentlyContinue | Where-Object {$_.displayname -eq 'DEF'}
$three = Get-ItemProperty -Path $Path -ErrorAction SilentlyContinue | Where-Object {$_.displayname -eq '123'}

if($one -or $two -or $three){

        $computer | Out-File C:\temp\MY.txt -Append
        }


} #end foreach

}
#only copies here outside of loop    
#$computer | Out-File C:\temp\MY.txt -Append

} #end main foreach loop

我希望只有在我的注册表配置单元中找到的机器才会被复制到文本文件中

标签: powershell

解决方案


推荐阅读