PowerShell获取域计算机的计算机名称和.Net Framework?

时间:2016-08-25 01:13:36

标签: powershell

我有这个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

1 个答案:

答案 0 :(得分:0)

您可以从注册表中读取计算机名,因此根本不需要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
相关问题