powershell - 我的远程注册表查找器中的 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
我希望只有在我的注册表配置单元中找到的机器才会被复制到文本文件中
解决方案
推荐阅读
- amazon-athena - 使用未来 presto 版本的功能
- php - DOM Pdf 在 codeigniter 框架中不起作用
- r - 在 R 中大小不等的多个 data.frame 对象中查找最新日期
- android - Android OS 语言查找:让 OS 知道应用的默认语言是什么
- mysql - MYSQL - 如何从具有 2 列的子查询更新表
- sql - “通过”VBA 附近的语法不正确
- java - 计算适合 docx 行的字符数
- python - 将字符串列表搜索到熊猫数据框中并返回包含该字符串的整行以构建新的 csv 文件
- git - 使用 git subtree 在项目中正确添加子目录
- python - Python Insightconnet 工作流程中的模式匹配