1

I have this PowerShell script that get's .Net framework version from computer. I also need to apply "Get-WmiObject Win32_ComputerSystem" to this script to have both, computer names as well as .Net framework version. How do I go about this?

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
  • This seems to be the same question as your question from yesterday http://stackoverflow.com/questions/39113247/powershell-to-get-net-framework-version-from-ad-computers – DAXaholic Aug 25 '16 at 03:47
  • That was the issue I fixed by myself. Now i wanted to add extra function to the script to get the computer name so that I can identify the .net framework version on all computers. So it's not the same question if you read carefully. If you can't help just check the next question and don't bother under voting my question. –  Aug 25 '16 at 04:30
  • @Samk80 The SO social contract is [be nice](http://stackoverflow.com/help/be-nice), so I'd advice against making snappy comments even if you feel frustrated. – vonPryz Aug 25 '16 at 05:47

1 Answers1

0

You can read the computername from registry, so no need for gwmi call at all. (WMI calls are slow, so it's preferable to avoid those if possible.) The computer name is stored in HKLM:\System\CurrentControlSet\Control\ComputerName\ComputerName, so amend the script to read it too from the registry.

That being said, the script looks like it expects you to read remote computer information, but it is only reading the local computer. And it does that as many times as you have AD computer objects too. That's because it never uses the objects that are passed from Get-ADComputer to the pipeline.

What you would need is remote connections to multiple registries by leveraging the pipeline like so,

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
Community
  • 1
  • 1
vonPryz
  • 22,996
  • 7
  • 54
  • 65
  • 1
    Thank you very much for your help. People like you are like gems to this world. –  Aug 25 '16 at 06:43