【发布时间】:2014-03-23 16:50:35
【问题描述】:
我拼凑了以下脚本,其中列出了本地系统上所有已安装的应用程序并将其写入日志文件,但我不知道在使用 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**************"
}
}
【问题讨论】:
-
为什么不使用 PowerShell Remoting 部署脚本,然后在主机会话中返回结果?我建议从您的函数中返回对象,而不是将文本写入日志文件。这将帮助您更有效地处理结果。
-
我唯一的问题是我们谈论的是 26 个域和超过 3,000 台服务器。我不能依靠主机级别的手动配置修改来适应脚本的执行。 PowerShell Remoting 是否不需要触摸每个以确保目标系统上的 powershell 和正确配置到位?
标签: powershell