【问题标题】:PowerShell to get Computer name and .Net Framework for Domain computers?PowerShell 获取域计算机的计算机名称和 .Net 框架?
【发布时间】:2017-01-01 07:02:27
【问题描述】:

我有这个 PowerShell 脚本,它可以从计算机获取 .Net 框架版本。我还需要将“Get-WmiObject Win32_ComputerSystem”应用于此脚本,以同时拥有计算机名称和 .Net 框架版本。我该怎么办?

Get-ADComputer -Filter * | ForEach { Get-ChildItem ‘HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP’ -recurse | Get-ItemProperty -name Version -EA 0 | Where { $_.PSChildName -match ‘^(?!S)\p{L}’} | Select PSChildName, Version } | Export-csv C:\temp\Netversion.csv

【问题讨论】:

  • 这个问题好像和你昨天问的一样stackoverflow.com/questions/39113247/…
  • 这是我自己解决的问题。现在我想在脚本中添加额外的函数来获取计算机名称,以便我可以识别所有计算机上的 .net 框架版本。因此,如果您仔细阅读,这不是同一个问题。如果您不能帮忙,请检查下一个问题,不要费心为我的问题投票。
  • @Samk80 SO 社会契约是be nice,所以即使你感到沮丧,我也建议不要制作活泼的 cmets。

标签: powershell


【解决方案1】:

您可以从注册表中读取计算机名,因此根本不需要gwmi 调用。 (WMI 调用很慢,因此如果可能,最好避免这些调用。)计算机名称存储在 HKLM:\System\CurrentControlSet\Control\ComputerName\ComputerName 中,因此请修改脚本以从注册表中读取它。

话虽如此,脚本看起来希望您读取远程计算机信息,但它只是读取本地计算机。并且它会执行的次数与您拥有 AD 计算机对象的次数一样多。这是因为它从不使用从 Get-ADComputer 传递到管道的对象。

您需要通过像这样利用管道将remote connections 发送到多个注册表,

Get-ADComputer -Filter * | ForEach {
    $reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', $_)
    $regKey= $Reg.OpenSubKey(<foo>)
    $value = $RegKey.GetValue(<bar>)
    # Do stuff with reg values, save in, say, collection of custom PSObjects
}
...
# Save the data into a file

【讨论】:

  • 非常感谢您的帮助。像你这样的人就像这个世界的宝石。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2022-10-17
  • 2010-12-18
  • 1970-01-01
  • 2011-06-14
  • 2012-11-03
相关资源
最近更新 更多